diff --git a/OsmAnd-java/src/net/osmand/data/FavouritePoint.java b/OsmAnd-java/src/net/osmand/data/FavouritePoint.java index 5eb38e8c58..fb151c4d57 100644 --- a/OsmAnd-java/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd-java/src/net/osmand/data/FavouritePoint.java @@ -2,7 +2,7 @@ package net.osmand.data; import java.io.Serializable; -public class FavouritePoint implements Serializable { +public class FavouritePoint implements Serializable, LocationPoint { private static final long serialVersionUID = 729654300829771466L; private String name; private String category = ""; @@ -16,6 +16,8 @@ public class FavouritePoint implements Serializable { public FavouritePoint(){ } + + public FavouritePoint(double latitude, double longitude, String name, String category) { this.latitude = latitude; this.longitude = longitude; diff --git a/OsmAnd-java/src/net/osmand/data/LocationPoint.java b/OsmAnd-java/src/net/osmand/data/LocationPoint.java new file mode 100644 index 0000000000..f09512a055 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/data/LocationPoint.java @@ -0,0 +1,16 @@ +package net.osmand.data; + +/** + * Created by Натали on 01.08.2014. + */ +public interface LocationPoint { + + public double getLatitude(); + + public double getLongitude(); + + public String getName(); + + public int getColor(); + +} diff --git a/OsmAnd/project.properties b/OsmAnd/project.properties index da75a72a89..8e1b6c02d0 100644 --- a/OsmAnd/project.properties +++ b/OsmAnd/project.properties @@ -11,5 +11,4 @@ split.density=false # Project target. target=android-19 -android.library.reference.1=../SherlockBar dex.force.jumbo=true diff --git a/OsmAnd/res/drawable-hdpi/ic_action_core_overflow_dark.png b/OsmAnd/res/drawable-hdpi/ic_action_core_overflow_dark.png new file mode 100644 index 0000000000..a074c10d05 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_action_core_overflow_dark.png differ diff --git a/OsmAnd/res/drawable-mdpi/ic_action_core_overflow_dark.png b/OsmAnd/res/drawable-mdpi/ic_action_core_overflow_dark.png new file mode 100644 index 0000000000..b6d614fcaf Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_action_core_overflow_dark.png differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_action_core_overflow_dark.png b/OsmAnd/res/drawable-xhdpi/ic_action_core_overflow_dark.png new file mode 100644 index 0000000000..7be3c2a4f1 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_action_core_overflow_dark.png differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_action_core_overflow_dark.png b/OsmAnd/res/drawable-xxhdpi/ic_action_core_overflow_dark.png new file mode 100644 index 0000000000..a0cb8a4182 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_action_core_overflow_dark.png differ diff --git a/OsmAnd/res/layout/waypoint_reached.xml b/OsmAnd/res/layout/waypoint_reached.xml new file mode 100644 index 0000000000..0613ff603e --- /dev/null +++ b/OsmAnd/res/layout/waypoint_reached.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/sherpafy.xml b/OsmAnd/res/values/sherpafy.xml index 281ea9d08f..3b53dcc85d 100644 --- a/OsmAnd/res/values/sherpafy.xml +++ b/OsmAnd/res/values/sherpafy.xml @@ -42,4 +42,5 @@ Start tour Download tour Sherpafy + See waypoint information diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1a59dc27b6..522f1b08bf 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1941,4 +1941,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Play sound on photo shot Choose whether to play a sound when shooting photos Invalid format: %s + Remove all diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index b82e5d2457..dd0717287d 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -29,6 +29,7 @@ import java.util.TimeZone; import net.osmand.Location; import net.osmand.PlatformUtil; +import net.osmand.data.LocationPoint; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -81,7 +82,7 @@ public class GPXUtilities { } - public static class WptPt extends GPXExtensions { + public static class WptPt extends GPXExtensions implements LocationPoint { public double lat; public double lon; public String name = null; @@ -95,7 +96,26 @@ public class GPXUtilities { public WptPt() { } - + + @Override + public int getColor() { + return getColor(0); + } + + @Override + public double getLatitude() { + return lat; + } + + @Override + public double getLongitude() { + return lon; + } + + @Override + public String getName() { + return name; + } public WptPt(double lat, double lon, long time, double ele, double speed, double hdop) { this.lat = lat; diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index dfeb05a2b3..0ad4ab0c07 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -19,6 +19,7 @@ import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleToast; import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.activities.DayNightHelper; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.api.SQLiteAPI; @@ -77,7 +78,7 @@ public class OsmandApplication extends Application { public static final String EXCEPTION_PATH = "exception.log"; //$NON-NLS-1$ private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(OsmandApplication.class); - + ResourceManager resourceManager = null; PoiFiltersHelper poiFilters = null; RoutingHelper routingHelper = null; @@ -104,10 +105,11 @@ public class OsmandApplication extends Application { private boolean applicationInitializing = false; private Locale preferredLocale = null; - + SQLiteAPI sqliteAPI; BRouterServiceConnection bRouterServiceConnection; + MapActivity mapActivity; @Override public void onCreate() { long timeToStart = System.currentTimeMillis(); @@ -838,4 +840,12 @@ public class OsmandApplication extends Application { getNavigationService().addUsageIntent(intent); } } + + public MapActivity getMapActivity() { + return mapActivity; + } + + public void setMapActivity(MapActivity mapActivity) { + this.mapActivity = mapActivity; + } } diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index 910120c03f..c1f6d688ea 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -2,11 +2,15 @@ package net.osmand.plus; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; import net.osmand.Location; import net.osmand.StateChangedListener; import net.osmand.data.LatLon; +import net.osmand.data.LocationPoint; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.util.MapUtils; @@ -21,7 +25,9 @@ public class TargetPointsHelper { private RoutingHelper routingHelper; private List> listeners = new ArrayList>(); private OsmandApplication ctx; - + private List visibleLocationPoints = new CopyOnWriteArrayList(); + private long locationPointsModified; + public TargetPointsHelper(OsmandApplication ctx){ this.ctx = ctx; this.settings = ctx.getSettings(); @@ -62,7 +68,50 @@ public class TargetPointsHelper { public List getIntermediatePoints() { return intermediatePoints; } - + + public List getVisibleLocationPoints() { + return visibleLocationPoints; + } + + public void addVisibleLocationPoint(LocationPoint lp) { + this.visibleLocationPoints.add(lp); + this.locationPointsModified = System.currentTimeMillis(); + sortVisibleLocationPoints(); + } + + public void removeAllVisiblePoints() { + this.locationPointsModified = System.currentTimeMillis(); + visibleLocationPoints.clear(); + } + + + public void sortVisibleLocationPoints() { + final Location lastLocation = ctx.getLocationProvider().getLastKnownLocation(); + if(lastLocation != null) { + Collections.sort(this.visibleLocationPoints, new Comparator() { + @Override + public int compare(LocationPoint locationPoint, LocationPoint locationPoint2) { + double d1 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(), + locationPoint.getLatitude(), locationPoint.getLongitude()); + double d2 = MapUtils.getDistance(lastLocation.getLatitude(), lastLocation.getLongitude(), + locationPoint2.getLatitude(), locationPoint2.getLongitude()); + return Double.compare(d1, d2); + } + }); + this.locationPointsModified = System.currentTimeMillis(); + } + } + + public long getLocationPointsModified() { + return locationPointsModified; + } + + public void removeVisibleLocationPoint(LocationPoint lp) { + this.visibleLocationPoints.remove(lp); + this.locationPointsModified = System.currentTimeMillis(); + } + + public List getIntermediatePointsWithTarget() { List res = new ArrayList(); res.addAll(intermediatePoints); @@ -71,7 +120,7 @@ public class TargetPointsHelper { } return res; } - + public List getIntermediatePointNamesWithTarget() { List res = new ArrayList(); res.addAll(intermediatePointNames); @@ -87,7 +136,7 @@ public class TargetPointsHelper { } return null; } - + /** * Clear the local and persistent waypoints list and destination. */ @@ -108,8 +157,8 @@ public class TargetPointsHelper { */ public void makeWayPointDestination(boolean updateRoute, int index){ pointToNavigate = intermediatePoints.remove(index); - settings.setPointToNavigate(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), - intermediatePointNames.remove(index)); + settings.setPointToNavigate(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), + intermediatePointNames.remove(index)); settings.deleteIntermediatePoint(index); updateRouteAndReferesh(updateRoute); } @@ -122,13 +171,13 @@ public class TargetPointsHelper { if(sz > 0) { settings.deleteIntermediatePoint(sz- 1); pointToNavigate = intermediatePoints.remove(sz - 1); - settings.setPointToNavigate(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), + settings.setPointToNavigate(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), intermediatePointNames.remove(sz - 1)); } } else { settings.deleteIntermediatePoint(index); intermediatePoints.remove(index); - intermediatePointNames.remove(index); + intermediatePointNames.remove(index); } updateRouteAndReferesh(updateRoute); } @@ -153,7 +202,7 @@ public class TargetPointsHelper { settings.getIntermediatePoints(), loc); } } - + private Location wrap(LatLon l) { if(l == null) { @@ -164,12 +213,12 @@ public class TargetPointsHelper { loc.setLongitude(l.getLongitude()); return loc; } - + public void addListener(StateChangedListener l) { listeners.add(l); } - - + + private void updateListeners() { for(StateChangedListener l : listeners) { l.stateChanged(null); @@ -184,15 +233,15 @@ public class TargetPointsHelper { readFromSettings(settings); updateRouteAndReferesh(updateRoute); } - + public void clearStartPoint(boolean updateRoute) { settings.clearPointToStart(); readFromSettings(settings); updateRouteAndReferesh(updateRoute); } - - - public void reorderAllTargetPoints(List point, + + + public void reorderAllTargetPoints(List point, List names, boolean updateRoute){ settings.clearPointToNavigate(); if (point.size() > 0) { @@ -206,8 +255,8 @@ public class TargetPointsHelper { readFromSettings(settings); updateRouteAndReferesh(updateRoute); } - - + + public boolean hasTooLongDistanceToNavigate() { if(settings.ROUTER_SERVICE.get() != RouteService.OSMAND) { return false; @@ -227,24 +276,24 @@ public class TargetPointsHelper { } return false; } - + public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate){ navigateToPoint(point, updateRoute, intermediate, null); } - + public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate, String historyName){ if(point != null){ if(intermediate < 0 || intermediate > intermediatePoints.size()) { if(intermediate > intermediatePoints.size()) { LatLon pn = getPointToNavigate(); if(pn != null) { - settings.insertIntermediatePoint(pn.getLatitude(), pn.getLongitude(), getPointNavigateDescription(), + settings.insertIntermediatePoint(pn.getLatitude(), pn.getLongitude(), getPointNavigateDescription(), intermediatePoints.size()); } } settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), historyName); } else { - settings.insertIntermediatePoint(point.getLatitude(), point.getLongitude(), historyName, + settings.insertIntermediatePoint(point.getLatitude(), point.getLongitude(), historyName, intermediate); } } else { @@ -254,7 +303,7 @@ public class TargetPointsHelper { readFromSettings(settings); updateRouteAndReferesh(updateRoute); } - + public void setStartPoint(LatLon startPoint, boolean updateRoute, String name) { if(startPoint != null) { settings.setPointToStart(startPoint.getLatitude(), startPoint.getLongitude(), name); @@ -264,7 +313,7 @@ public class TargetPointsHelper { readFromSettings(settings); updateRouteAndReferesh(updateRoute); } - + public boolean checkPointToNavigate(){ if(pointToNavigate == null){ ctx.showToastMessage(R.string.mark_final_location_first); @@ -272,7 +321,7 @@ public class TargetPointsHelper { } return true; } - + public boolean checkPointToNavigateShort(){ if(pointToNavigate == null){ ctx.showShortToastMessage(R.string.mark_final_location_first); @@ -284,6 +333,4 @@ public class TargetPointsHelper { public Location getPointToStartLocation() { return wrap(getPointToStart()); } - - } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java index 6f24115a79..c8e290e32c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesActivity.java @@ -6,6 +6,7 @@ package net.osmand.plus.activities; import java.io.File; import java.util.ArrayList; +import android.content.Intent; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -36,6 +37,10 @@ public class FavouritesActivity extends SherlockFragmentActivity { private static final String FAVOURITES_INFO = "FAVOURITES_INFO"; private static final String TRACKS = "TRACKS"; private static final String SELECTED_TRACK = "SELECTED_TRACK"; + public static int FAVORITES_TAB = 0; + public static int GPX_TAB = 1; + public static int SELECTED_GPX_TAB = 2; + public static String TAB_PARAM = "TAB_PARAM"; private TabsAdapter mTabsAdapter; private TabSpec selectedTrack; private TabHost tabHost; @@ -85,7 +90,15 @@ public class FavouritesActivity extends SherlockFragmentActivity { AvailableGPXFragment.class, null); selectedTrack = mTabsAdapter.addTab(tabHost.newTabSpec(SELECTED_TRACK).setIndicator(getString(R.string.selected_track)), SelectedGPXFragment.class, null); - tabHost.setCurrentTab(tab); + Intent intent = getIntent(); + if(intent != null) { + int tt = intent.getIntExtra(TAB_PARAM, -1); + if(tt >= 0) { + tabHost.setCurrentTab(tt); + } + } else { + tabHost.setCurrentTab(tab); + } updateSelectedTracks(); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index ff2e996ee6..fd14fabdfc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -301,6 +301,7 @@ public class MapActivity extends AccessibleActivity { } settings.MAP_ACTIVITY_ENABLED.set(true); + app.setMapActivity(this); checkExternalStorage(); showAndHideMapPosition(); @@ -559,6 +560,7 @@ public class MapActivity extends AccessibleActivity { settings.setLastKnownMapZoom(mapView.getZoom()); settings.MAP_ACTIVITY_ENABLED.set(false); + app.setMapActivity(null); app.getResourceManager().interruptRendering(); app.getResourceManager().setBusyIndicator(null); OsmandPlugin.onMapActivityPause(this); diff --git a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java index 93a2fab224..5810d31ad6 100644 --- a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java @@ -4,29 +4,24 @@ import java.io.File; import java.util.*; import android.content.Context; +import android.content.Intent; import android.view.Gravity; import android.view.LayoutInflater; import android.widget.Button; import android.widget.FrameLayout; import android.widget.TextView; import net.osmand.data.LatLon; -import net.osmand.plus.ApplicationMode; -import net.osmand.plus.GPXUtilities; +import net.osmand.plus.*; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.Route; import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.R; -import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.sherpafy.WaypointDialogHelper; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.util.MapUtils; -import android.content.Intent; import android.graphics.Paint; import android.os.AsyncTask; import android.text.format.DateFormat; @@ -242,6 +237,8 @@ public class RoutePointsPlugin extends OsmandPlugin { routeStepsControl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { +// FavouritesDbHelper fp = map.getMyApplication().getFavorites(); +// app.getTargetPointsHelper().addVisibleLocationPoint(fp.getFavouritePoints().get(new Random().nextInt(fp.getFavouritePoints().size()))); Intent intent = new Intent(app, RoutePointsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); app.startActivity(intent); @@ -252,6 +249,7 @@ public class RoutePointsPlugin extends OsmandPlugin { return routeStepsControl; } + public class RoutePoint { boolean isNextNavigate; int gpxOrder; diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 15f0151e37..2c73c90814 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -1,5 +1,6 @@ package net.osmand.plus.routing; +import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator; import gnu.trove.list.array.TIntArrayList; import java.util.ArrayList; @@ -13,6 +14,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.data.DataTileManager; import net.osmand.data.LatLon; +import net.osmand.data.LocationPoint; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.R; @@ -30,7 +32,7 @@ public class RouteCalculationResult { private final List directions; private final List segments; private final List alarmInfo; - private final List waypoints; + private final List waypoints; private final String errorMessage; private final int[] listDistance; private final int[] intermediatePoints; @@ -59,11 +61,11 @@ public class RouteCalculationResult { this.directions = new ArrayList(); this.alarmInfo = new ArrayList(); this.waypointIndexes = new int[0]; - this.waypoints = new ArrayList(); + this.waypoints = new ArrayList(); } public RouteCalculationResult(List list, List directions, RouteCalculationParams params, - DataTileManager waypointsTm) { + DataTileManager waypointsTm) { this.routingTime = 0; this.errorMessage = null; this.intermediatePoints = new int[params.intermediates == null ? 0 : params.intermediates.size()]; @@ -89,12 +91,12 @@ public class RouteCalculationResult { calculateIntermediateIndexes(params.ctx, this.locations, params.intermediates, localDirections, this.intermediatePoints); this.directions = Collections.unmodifiableList(localDirections); updateDirectionsTime(this.directions, this.listDistance); - this.waypoints = new ArrayList(); + this.waypoints = new ArrayList(); this.waypointIndexes = calculateWaypointIndexes(list, waypointsTm, waypoints); } public RouteCalculationResult(List list, Location start, LatLon end, List intermediates, - Context ctx, boolean leftSide, float routingTime) { + Context ctx, boolean leftSide, float routingTime,DataTileManager waypointsTm) { this.routingTime = routingTime; List computeDirections = new ArrayList(); this.errorMessage = null; @@ -113,17 +115,18 @@ public class RouteCalculationResult { this.directions = Collections.unmodifiableList(computeDirections); updateDirectionsTime(this.directions, this.listDistance); this.alarmInfo = Collections.unmodifiableList(alarms); - this.waypointIndexes = new int[0]; - this.waypoints = new ArrayList(); + this.waypoints = new ArrayList(); + + this.waypointIndexes = calculateWaypointIndexes(this.locations, waypointsTm, waypoints); } - public List getWaypointsToAnnounce(Location loc) { + public List getWaypointsToAnnounce(Location loc) { if (currentWaypointGPX != lastWaypointGPX && loc != null) { - ArrayList points = new ArrayList(); + ArrayList points = new ArrayList(); Location next = locations.get(currentRoute); float dist = loc.distanceTo(next); while (currentWaypointGPX < lastWaypointGPX) { - WptPt w = waypoints.get(currentWaypointGPX); + WptPt w = (WptPt) waypoints.get(currentWaypointGPX); if(MapUtils.getDistance(w.lat, w.lon, next.getLatitude(), next.getLongitude()) > dist + 50) { currentWaypointGPX++; } else { @@ -131,7 +134,7 @@ public class RouteCalculationResult { } } while (currentWaypointGPX < lastWaypointGPX) { - WptPt w = waypoints.get(currentWaypointGPX); + WptPt w = (WptPt) waypoints.get(currentWaypointGPX); if(MapUtils.getDistance(w.lat, w.lon, loc.getLatitude(), next.getLongitude()) < 60) { currentWaypointGPX++; points.add(w); @@ -519,27 +522,27 @@ public class RouteCalculationResult { * PREPARATION * */ - private int[] calculateWaypointIndexes(List list, DataTileManager waypointsTm, List waypoints) { + private int[] calculateWaypointIndexes(List list, DataTileManager waypointsTm, List waypoints) { if(waypointsTm == null || waypointsTm.isEmpty() || list.size() == 0) { return new int[0]; } TIntArrayList ls = new TIntArrayList(); Location loc = list.get(0); Location ploc = list.get(0); - Set added = new HashSet(); + Set added = new HashSet(); int prev31x = MapUtils.get31TileNumberX(loc.getLatitude()); int prev31y = MapUtils.get31TileNumberY(loc.getLongitude()); for(int j = 1; j < list.size(); j++) { loc = list.get(j); int t31x = MapUtils.get31TileNumberX(loc.getLatitude()); int t31y = MapUtils.get31TileNumberY(loc.getLongitude()); - List ws = waypointsTm.getObjects(Math.min(prev31x, t31x) - Math.abs(t31x - prev31x) / 4, + List ws = waypointsTm.getObjects(Math.min(prev31x, t31x) - Math.abs(t31x - prev31x) / 4, Math.min(prev31y, t31y) - Math.abs(t31y - prev31y) / 4, Math.max(prev31x, t31x) + Math.abs(t31x - prev31x) / 4, Math.max(prev31y, t31y) + Math.abs(t31y - prev31y) / 4); - for(WptPt w : ws) { + for(LocationPoint w : ws) { if (added.contains(w)) { - double ds = MapUtils.getOrthogonalDistance(w.lat, w.lon, ploc.getLatitude(), ploc.getLongitude(), loc.getLatitude(), + double ds = MapUtils.getOrthogonalDistance(w.getLatitude(), w.getLongitude(), ploc.getLatitude(), ploc.getLongitude(), loc.getLatitude(), loc.getLongitude()); if (ds < 160) { ls.add(j); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java index ea0ca48abd..c29bcb0517 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java @@ -22,10 +22,12 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; +import com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator; import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.DataTileManager; +import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities; @@ -775,8 +777,13 @@ public class RouteProvider { // something really strange better to see that message on the scren return emptyResult(); } else { + DataTileManager mngr = new DataTileManager(17); + List points = params.ctx.getFavorites().getFavouritePoints(); + for(FavouritePoint point : points){ + mngr.registerObject(point.getLatitude(), point.getLongitude(), point); + } RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end, - params.intermediates, params.ctx, params.leftSide, ctx.routingTime); + params.intermediates, params.ctx, params.leftSide, ctx.routingTime, mngr); return res; } } catch (RuntimeException e) { diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index eae91e3be7..876c1864db 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -10,6 +10,7 @@ import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; +import net.osmand.data.LocationPoint; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; @@ -25,6 +26,7 @@ import net.osmand.plus.routing.AlarmInfo.AlarmInfoType; import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.RouteService; +import net.osmand.plus.sherpafy.WaypointDialogHelper; import net.osmand.plus.voice.CommandPlayer; import net.osmand.router.RouteCalculationProgress; import net.osmand.router.RouteSegmentResult; @@ -318,16 +320,17 @@ public class RoutingHelper { private void announceGpxWaypoints(Location currentLocation) { if (currentLocation != null) { - List wpt = route.getWaypointsToAnnounce(currentLocation); + List wpt = route.getWaypointsToAnnounce(currentLocation); if (wpt.size() > 0) { String s = ""; - for (WptPt w : wpt) { - if(!Algorithms.isEmpty(w.name)) { - s = w.name +","; + for (LocationPoint w : wpt) { + if(!Algorithms.isEmpty(w.getName())) { + s = w.getName() +","; } } if(!Algorithms.isEmpty(s)) { voiceRouter.announceWaypoint(s); +// dialogHelper.addWptDialog(wpt.get(0)); } } } diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java new file mode 100644 index 0000000000..49193e639e --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/sherpafy/WaypointDialogHelper.java @@ -0,0 +1,251 @@ +package net.osmand.plus.sherpafy; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Color; +import android.os.AsyncTask; +import android.os.SystemClock; +import android.text.Spannable; +import android.text.style.ForegroundColorSpan; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.*; +import net.osmand.Location; +import net.osmand.data.LatLon; +import net.osmand.data.LocationPoint; +import net.osmand.plus.*; +import net.osmand.plus.activities.FavouritesActivity; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.views.MapControlsLayer; +import net.osmand.util.MapUtils; + +import java.util.List; + +/** + * Created by Denis on 25.07.2014. + */ +public class WaypointDialogHelper { + private MapActivity mapActivity; + private OsmandApplication app; + private FrameLayout mainLayout; + private TargetPointsHelper targetPointsHelper; + + public static boolean OVERLAP_LAYOUT = true; + private long uiModified; + private View closePointDialog; + + public WaypointDialogHelper(MapActivity mapActivity) { + this.app = mapActivity.getMyApplication(); + targetPointsHelper = this.app.getTargetPointsHelper(); + this.mapActivity = mapActivity; + this.mainLayout = (FrameLayout) ((FrameLayout) mapActivity.getLayout()).getChildAt(0); + } + + public void updateDialog() { + List vlp = targetPointsHelper.getVisibleLocationPoints(); + long locationPointsModified = targetPointsHelper.getLocationPointsModified(); + if (locationPointsModified != uiModified) { + uiModified = locationPointsModified; + if (vlp.isEmpty()) { + removeDialog(); + } else { + final LocationPoint point = vlp.get(0); + boolean created = false; + if (closePointDialog == null) { + created = true; + final LayoutInflater vi = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + closePointDialog = vi.inflate(R.layout.waypoint_reached, null); + } + + createView(closePointDialog, point); + closePointDialog.setBackgroundColor(mapActivity.getResources().getColor(R.color.color_black)); + ((TextView)closePointDialog.findViewById(R.id.waypoint_text)).setTextColor(Color.WHITE); + View all = closePointDialog.findViewById(R.id.all_points); + all.setVisibility(vlp.size() <= 1 ? View.GONE : View.VISIBLE); + all.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showAllDialog(); + } + }); + + View btnN = closePointDialog.findViewById(R.id.info_close); + btnN.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + targetPointsHelper.removeVisibleLocationPoint(point); + updateDialog(); + } + }); + + if (created) { + mainLayout.addView(closePointDialog, getDialogLayoutParams()); + waitBeforeLayoutIsResized(closePointDialog); + } + } + } + } + + private void createView(View localView, final LocationPoint point) { + TextView text = (TextView) localView.findViewById(R.id.waypoint_text); + text.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + itemClick(point); + } + }); + + ((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate(mapActivity, point.getColor())); + Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation(); +// LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation(); + String distance; + if (lastKnownMapLocation != null) { + int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), + lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); + distance = OsmAndFormatter.getFormattedDistance(dist, app) + " "; + } else { + distance = ""; + } + text.setText(distance + point.getName(), TextView.BufferType.SPANNABLE); + if (distance.length() > 0) { + ((Spannable) text.getText()).setSpan( + new ForegroundColorSpan(mapActivity.getResources().getColor(R.color.color_distance)), 0, distance.length() - 1, + 0); + } + } + + private void itemClick(LocationPoint point) { + final Intent favorites = new Intent(mapActivity, app.getAppCustomization().getFavoritesActivity()); + favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + favorites.putExtra(FavouritesActivity.TAB_PARAM, + point instanceof GPXUtilities.WptPt ? FavouritesActivity.GPX_TAB : FavouritesActivity.FAVORITES_TAB); + mapActivity.startActivity(favorites); + } + + public void removeDialog() { + if (closePointDialog != null) { + mainLayout.removeView(closePointDialog); + closePointDialog = null; + shiftButtons(0); + } + } + + private FrameLayout.LayoutParams getDialogLayoutParams() { + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); + params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; + return params; + } + + private boolean checkIfDialogExists() { + if (mainLayout == null) { + return true; + } + + if (mainLayout.findViewById(R.id.package_delivered_layout) != null) { + return false; + } + return true; + } + + private void shiftButtons(int height) { + MapControlsLayer mapControls = mapActivity.getMapLayers().getMapControlsLayer(); + if (mapControls != null) { + mapControls.shiftLayout(height); + } + } + + + private void waitBeforeLayoutIsResized(View reachedView) { + //this async task is needed because layout height is not set + // right after you add it so we need to w8 some time + new AsyncTask() { + int height; + + @Override + protected Void doInBackground(View... params) { + for (int i = 0; i < 10; i++) { + SystemClock.sleep(50); + height = params[0].getHeight(); + if (params[0].getHeight() > 0) { + break; + } + } + return null; + } + + protected void onPostExecute(Void result) { + if (height > 0 && OVERLAP_LAYOUT) { + shiftButtons(height); + } + } + }.execute(reachedView); + } + + public void showAllDialog(){ + final List visibleLocationPoints = targetPointsHelper.getVisibleLocationPoints(); + final ArrayAdapter listAdapter = new ArrayAdapter(mapActivity, R.layout.waypoint_reached, R.id.title, + visibleLocationPoints) { + @Override + public View getView(final int position, View convertView, ViewGroup parent) { + // User super class to create the View + View v = convertView; + if (v == null) { + v = mapActivity.getLayoutInflater().inflate(R.layout.waypoint_reached, null); + int vl = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, mapActivity.getResources() + .getDisplayMetrics()); + final LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(vl, vl); + ll.setMargins(vl / 4, vl / 4, vl / 4, vl / 4); + v.findViewById(R.id.waypoint_icon).setLayoutParams(ll); + } + createView(v, getItem(position)); + + View remove = v.findViewById(R.id.info_close); + ((ImageButton) remove).setImageDrawable(mapActivity.getResources().getDrawable( + app.getSettings().isLightContent()? R.drawable.ic_action_gremove_light: + R.drawable.ic_action_gremove_dark)); + remove.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + LocationPoint point = targetPointsHelper.getVisibleLocationPoints().get(position); + remove(point); + targetPointsHelper.removeVisibleLocationPoint(point); + notifyDataSetChanged(); + } + }); + + return v; + } + }; + + ListView listView = new ListView(mapActivity); + listView.setAdapter(listAdapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + itemClick(visibleLocationPoints.get(i)); + } + }); + +// Dialog dlg = new Dialog(mapActivity); +// dlg.setContentView(listView); +// dlg.show(); + AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); + builder.setView(listView); + builder.setPositiveButton(R.string.default_buttons_ok, null); + builder.setNegativeButton(mapActivity.getString(R.string.hide_all_waypoints), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + targetPointsHelper.removeAllVisiblePoints(); + updateDialog(); + } + }); + builder.show(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 28355c9398..d65b7e45f4 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -3,12 +3,14 @@ package net.osmand.plus.views; import java.util.ArrayList; import java.util.List; +import android.view.ViewParent; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.sherpafy.WaypointDialogHelper; import net.osmand.plus.views.controls.MapRoutePlanControl; import net.osmand.plus.views.controls.MapRoutePreferencesControl; import net.osmand.plus.views.controls.MapCancelControl; @@ -59,10 +61,12 @@ public class MapControlsLayer extends OsmandMapLayer { private LinearLayout transparencyBarLayout; private static CommonPreference settingsToTransparency; private OsmandSettings settings; + private WaypointDialogHelper waypointDialogHelper; public MapControlsLayer(MapActivity activity){ this.mapActivity = activity; settings = activity.getMyApplication().getSettings(); + waypointDialogHelper = new WaypointDialogHelper(activity); } @Override @@ -176,9 +180,11 @@ public class MapControlsLayer extends OsmandMapLayer { checkVisibilityAndDraw(showRouteCalculationControls, zoomSideControls, canvas, tileBox, nightMode); // the last one to check other controls visibility - int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ? zoomControls.getHeight() : 0; + int vmargin = mapNavigationControl.isVisible() || zoomControls.isVisible() ? + (zoomControls.getHeight() + zoomControls.getTotalVerticalMargin()): 0; rulerControl.setVerticalMargin(vmargin); checkVisibilityAndDraw(true, rulerControl, canvas, tileBox, nightMode); + waypointDialogHelper.updateDialog(); } private void updatextColor(int textColor, int shadowColor, MapControls... mc) { @@ -189,7 +195,7 @@ public class MapControlsLayer extends OsmandMapLayer { private void checkVisibilityAndDraw(boolean visibility, MapControls controls, Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) { - if(visibility != controls.isVisible()){ + if(visibility != controls.isVisible() ){ if(visibility) { controls.show((FrameLayout) mapActivity.getMapView().getParent()); } else { @@ -298,6 +304,23 @@ public class MapControlsLayer extends OsmandMapLayer { transparencyBarLayout.setVisibility(View.GONE); settingsToTransparency = null; } - } + } + public void shiftLayout(int height) { + FrameLayout parent = (FrameLayout) mapActivity.getMapView().getParent(); + parent.requestLayout(); + for(MapControls mc : allControls) { + if(mc.isBottom()){ + mc.setExtraVerticalMargin(height); + if( mc.isVisible()) { + mc.forceHide(parent); + mc.show(parent); + } + } + } + } + + public WaypointDialogHelper getWaypointDialogHelper() { + return waypointDialogHelper; + } } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java b/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java index 27bd4571e2..8608a77c34 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapControls.java @@ -1,7 +1,9 @@ package net.osmand.plus.views.controls; import net.osmand.data.RotatedTileBox; +import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.sherpafy.WaypointDialogHelper; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import android.content.Context; import android.graphics.Canvas; @@ -31,7 +33,8 @@ public abstract class MapControls { protected int width; protected int height; protected Runnable notifyClick; - + private int extraVerticalMargin; + public MapControls(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) { this.mapActivity = mapActivity; this.showUIHandler = showUIHandler; @@ -56,12 +59,15 @@ public abstract class MapControls { applyAttributes(ctx, parent, button, stringId, resourceId, 0); return button; } - + + public int getTotalVerticalMargin() { + return extraVerticalMargin + vmargin; + } + protected Button addButton(FrameLayout parent, int stringId, int resourceId) { return addButton(parent, stringId, resourceId, 0); } - - protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) { + protected Button addButton(FrameLayout parent, int stringId, int resourceId, int extraMargin) { Context ctx = mapActivity; Button button = new Button(ctx); applyAttributes(ctx, parent, button, stringId, resourceId, extraMargin); @@ -92,15 +98,20 @@ public abstract class MapControls { params.rightMargin = margin + extraMargin; } if((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) { - params.bottomMargin = vmargin; + params.bottomMargin = vmargin + extraVerticalMargin; } else { - params.topMargin = vmargin; + params.topMargin = vmargin + extraVerticalMargin; } - parent.addView(button, params); + button.setLayoutParams(params); + parent.addView(button); button.setEnabled(true); mapActivity.accessibleContent.add(button); } - + + public int getGravity() { + return gravity; + } + protected void removeButton(FrameLayout layout, View b) { layout.removeView(b); mapActivity.accessibleContent.remove(b); @@ -170,7 +181,7 @@ public abstract class MapControls { return (Gravity.LEFT & gravity) == Gravity.LEFT; } - protected boolean isBottom() { + public boolean isBottom() { return (Gravity.BOTTOM & gravity) == Gravity.BOTTOM; } @@ -193,4 +204,8 @@ public abstract class MapControls { public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { return false; } + + public void setExtraVerticalMargin(int extraVerticalMargin) { + this.extraVerticalMargin = extraVerticalMargin; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java index 430dadda5c..1e2c292136 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapNavigateControl.java @@ -193,7 +193,8 @@ public class MapNavigateControl extends MapControls { private void drawCount(Canvas canvas, RotatedTileBox tb) { - if (navigateShadow.getBounds().width() == 0 && navigateButton.getWidth() > 0) { + if ((navigateShadow.getBounds().width() == 0 && navigateButton.getWidth() > 0 )|| + navigateShadow.getBounds().bottom != navigateButton.getBottom()) { navigateShadow.setBounds(navigateButton.getLeft() - 2, navigateButton.getTop() - (int) (18 * scaleCoefficient), navigateButton.getRight(), navigateButton.getBottom()); } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java index b43bc3763e..7b99e389a4 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java @@ -248,6 +248,7 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio @Override public void hideControls(FrameLayout layout) { removeButton(layout, infoButton); + hideDialog(); controlVisible = false; }