Refactor waypoints

This commit is contained in:
Victor Shcherb 2014-08-19 22:40:56 +02:00
parent 34a99dbb1f
commit e826fd0303
17 changed files with 133 additions and 86 deletions

View file

@ -26,8 +26,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:singleLine="true"
android:maxLines="2"
android:ellipsize="end"
android:clickable="true"
android:focusable="true"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textSize="18sp"/>

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="speak_favorites">Announce Favorites</string>
<string name="speak_poi">Announce POI</string>
<string name="download_additional_maps">Download missing maps %1$s (%2$d MB)?</string>
<string name="more">More...</string>
<string name="rendering_value_browse_map_name">Browse map</string>

View file

@ -2,6 +2,8 @@ package net.osmand.data;
import java.io.Serializable;
import android.content.Context;
public class FavouritePoint implements Serializable, LocationPoint {
private static final long serialVersionUID = 729654300829771466L;
private String name;
@ -62,6 +64,10 @@ public class FavouritePoint implements Serializable, LocationPoint {
this.category = category;
}
public String getName(Context ctx) {
return name;
}
public String getName() {
return name;
}

View file

@ -1,5 +1,6 @@
package net.osmand.data;
import net.osmand.plus.voice.CommandBuilder;
import android.content.Context;
/**
*/
@ -9,7 +10,7 @@ public interface LocationPoint {
public double getLongitude();
public String getName();
public String getName(Context ctx);
public int getColor();

View file

@ -113,7 +113,7 @@ public class GPXUtilities {
}
@Override
public String getName() {
public String getName(Context ctx) {
return name;
}

View file

@ -819,8 +819,8 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> GPX_ROUTE_CALC = new BooleanPreference("calc_gpx_route", false).makeGlobal().cache();
public final OsmandPreference<Boolean> GPX_SPEAK_WPT = new BooleanPreference("speak_gpx_wpt", true).makeGlobal().cache();
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_FAVORITES = new BooleanPreference("announce_nearby_favorites", true).makeGlobal().cache();
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_POI = new BooleanPreference("announce_nearby_poi", true).makeGlobal().cache();
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_FAVORITES = new BooleanPreference("announce_nearby_favorites", true).makeProfile().cache();
public final OsmandPreference<Boolean> ANNOUNCE_NEARBY_POI = new BooleanPreference("announce_nearby_poi", true).makeProfile().cache();
public final OsmandPreference<Boolean> SHOW_NEARBY_POI = new BooleanPreference("show_nearby_poi", true).makeGlobal().cache();
public final OsmandPreference<Boolean> SHOW_NEARBY_FAVORIES = new BooleanPreference("show_nearby_favorites", true).makeGlobal().cache();

View file

@ -9,6 +9,7 @@ import android.content.Context;
import net.osmand.Location;
import net.osmand.StateChangedListener;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.util.MapUtils;
@ -23,7 +24,7 @@ public class TargetPointsHelper {
private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>();
private OsmandApplication ctx;
public static class TargetPoint {
public static class TargetPoint implements LocationPoint {
public LatLon point;
public String name;
public int index;
@ -48,11 +49,18 @@ public class TargetPointsHelper {
return null;
}
private String vName() {
if(name.trim().length()==0) {
return "";
}
return ": " + name;
}
public String getVisibleName(Context ctx) {
if (!intermediate) {
return ctx.getString(R.string.destination_point, "") + " : " + name;
return ctx.getString(R.string.destination_point, "") + vName();
} else {
return (index + 1) + ". " + ctx.getString(R.string.intermediate_point, "") + " : " + name;
return (index + 1) + ". " + ctx.getString(R.string.intermediate_point, "") + vName();
}
}
@ -63,6 +71,21 @@ public class TargetPointsHelper {
public double getLongitude() {
return point.getLongitude();
}
@Override
public String getName(Context ctx) {
return getVisibleName(ctx);
}
@Override
public int getColor() {
return 0;
}
@Override
public boolean isVisible() {
return false;
}
}

View file

@ -834,9 +834,12 @@ public class MapActivityActions implements DialogProvider {
.listen(new OnContextMenuClick() {
@Override
public void onContextMenuClick(int itemId, int pos, boolean isChecked, DialogInterface dialog) {
WaypointDialogHelper.showWaypointsDialog(getMyApplication(), mapActivity,
getMyApplication().getWaypointHelper().getAllPoints());
// openIntermediatePointsDialog();
if (getMyApplication().getWaypointHelper().isRouteCalculated()) {
WaypointDialogHelper.showWaypointsDialog(getMyApplication(), mapActivity,
getMyApplication().getWaypointHelper().getAllPoints());
} else {
openIntermediatePointsDialog();
}
}
}).reg();
}

View file

@ -238,8 +238,12 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
return true;
} else if (preference == speakAlarms) {
showBooleanSettings(new String[] { getString(R.string.speak_street_names), getString(R.string.speak_traffic_warnings), getString(R.string.speak_cameras),
getString(R.string.speak_speed_limit) }, new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS,
settings.SPEAK_SPEED_CAMERA , settings.SPEAK_SPEED_LIMIT});
getString(R.string.speak_speed_limit),
getString(R.string.speak_favorites),
getString(R.string.speak_poi)},
new OsmandPreference[] { settings.SPEAK_STREET_NAMES, settings.SPEAK_TRAFFIC_WARNINGS,
settings.SPEAK_SPEED_CAMERA , settings.SPEAK_SPEED_LIMIT,
settings.ANNOUNCE_NEARBY_FAVORITES, settings.ANNOUNCE_NEARBY_POI});
return true;
}
return false;

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
@ -13,6 +14,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
@ -83,7 +85,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
updatePointInfoView(app, mapActivity, closePointDialog, point);
View all = closePointDialog.findViewById(R.id.all_points);
all.setVisibility(many.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);
@ -94,18 +96,18 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
});
View btnN = closePointDialog.findViewById(R.id.info_close);
btnN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
waypointHelper.removeVisibleLocationPoint(point);
updateDialog();
}
});
mainLayout.addView(closePointDialog, getDialogLayoutParams());
waitBeforeLayoutIsResized(closePointDialog);
}
View btnN = closePointDialog.findViewById(R.id.info_close);
btnN.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
waypointHelper.removeVisibleLocationPoint(point);
updateDialog();
}
});
}
}
@ -124,17 +126,14 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
});
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(ctx));
Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
String dd = "";
if (lastKnownMapLocation != null) {
int dist = wh.getRouteDistance(ps);
dd = OsmAndFormatter.getFormattedDistance(dist, app) ;
if(ps.deviationDistance > 0 ) {
dd += "\n "+OsmAndFormatter.getFormattedDistance(ps.deviationDistance, app);
}
// Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
int dist = wh.getRouteDistance(ps);
String dd = OsmAndFormatter.getFormattedDistance(dist, app);
if (ps.deviationDistance > 0) {
dd += "\n " + OsmAndFormatter.getFormattedDistance(ps.deviationDistance, app);
}
textDist.setText(dd);
text.setText(point.getName());
text.setText(point.getName(app));
// ((Spannable) text.getText()).setSpan(
// new ForegroundColorSpan(ctx.getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
// 0);
@ -211,6 +210,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
public void onClick(View view) {
LocationPointWrapper point = visibleLocationPoints.get(position);
remove(point);
deletedPoints.add(point);
notifyDataSetChanged();
}
});
@ -244,9 +244,20 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
private static void showOnMap(OsmandApplication app, MapActivity ctx, LocationPoint locationPoint) {
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
int fZoom = ctx.getMapView().getZoom() < 15 ? 15 : ctx.getMapView().getZoom();
thread.startMoving(locationPoint.getLatitude(), locationPoint.getLongitude(), fZoom, true);
// ctx.getMapView().setIntZoom(fZoom);
// ctx.getMapView().setLatLon(point.getLatitude(), point.getLongitude());
if (thread.isAnimating()) {
ctx.getMapView().setIntZoom(fZoom);
ctx.getMapView().setLatLon(locationPoint.getLatitude(), locationPoint.getLongitude());
} else if (MapUtils.getDistance(ctx.getMapView().getLatitude(), ctx.getMapView().getLongitude(),
locationPoint.getLatitude(), locationPoint.getLongitude()) < 10) {
ctx.getMapLayers().getContextMenuLayer().setSelectedObject(locationPoint);
ctx.getMapLayers()
.getContextMenuLayer()
.setLocation(new LatLon(locationPoint.getLatitude(), locationPoint.getLongitude()),
locationPoint.getName(ctx));
} else {
thread.startMoving(locationPoint.getLatitude(), locationPoint.getLongitude(), fZoom, true);
}
}

View file

@ -21,6 +21,7 @@ import net.osmand.data.LocationPoint;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -240,7 +241,6 @@ public class WaypointHelper {
Location lastKnownLocation = app.getRoutingHelper().getLastProjection();
if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
for (int type = 0; type < locationPoints.size(); type++) {
String nameToAnnounce = null;
int currentRoute = route.getCurrentRoute();
List<LocationPoint> approachPoints = new ArrayList<LocationPoint>();
List<LocationPoint> announcePoints = new ArrayList<LocationPoint>();
@ -260,10 +260,10 @@ public class WaypointHelper {
double d1 = MapUtils.getDistance(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(),
point.getLatitude(), point.getLongitude());
Integer state = locationPointsStates.get(point);
System.out.println("!!! " + d1 + " " + point.getName(app));
if (state != null && state.intValue() == ANNOUNCED_ONCE
&& getVoiceRouter()
.isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS)) {
nameToAnnounce = (nameToAnnounce == null ? "" : ", ") + point.getName();
locationPointsStates.remove(point);
announcePoints.add(point);
} else if ((state == null || state == NOT_ANNOUNCED)
@ -312,6 +312,10 @@ public class WaypointHelper {
return app.getRoutingHelper().getVoiceRouter();
}
public boolean isRouteCalculated() {
return route != null && !route.isEmpty();
}
public List<LocationPointWrapper> getAllPoints() {
List<LocationPointWrapper> points = new ArrayList<WaypointHelper.LocationPointWrapper>();
List<List<LocationPointWrapper>> local = locationPoints;
@ -323,10 +327,16 @@ public class WaypointHelper {
}
}
List<TargetPoint> wts = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
for(int k = 0; k < wts.size() ; k++) {
TargetPoint tp = wts.get(wts.size() - k - 1);
int routeIndex = k == 0 ? Integer.MAX_VALUE : route.getIndexOfIntermediate(k);
points.add(new LocationPointWrapper(route, TARGETS, new TargetPointHelper(tp), 0, routeIndex));
for (int k = 0; k < wts.size(); k++) {
final int index = wts.size() - k - 1;
TargetPoint tp = wts.get(index);
int routeIndex ;
if(route == null) {
routeIndex = k == 0 ? Integer.MAX_VALUE : index;
} else {
routeIndex = k == 0 ? route.getImmutableAllLocations().size() - 1 : route.getIndexOfIntermediate(k - 1);
}
points.add(new LocationPointWrapper(route, TARGETS, tp, 0, routeIndex));
}
sortList(points);
return points;
@ -396,7 +406,10 @@ public class WaypointHelper {
public int compare(LocationPointWrapper olhs, LocationPointWrapper orhs) {
int lhs = olhs.routeIndex;
int rhs = orhs.routeIndex;
return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
if(lhs == rhs) {
return Float.compare(olhs.deviationDistance, orhs.deviationDistance);
}
return lhs < rhs ? -1 : 1;
}
});
}
@ -555,7 +568,10 @@ public class WaypointHelper {
return uiCtx.getResources().getDrawable(RenderingIcons.getBigIconResourceId(value.toString()));
}
return null;
// } else if(type == TARGETS) {
} else if(type == TARGETS) {
return uiCtx.getResources().getDrawable(
!((TargetPoint)point).intermediate? R.drawable.list_destination:
R.drawable.list_intermediate);
} else {
return FavoriteImageDrawable.getOrCreate(uiCtx, point.getColor());
}
@ -603,8 +619,8 @@ public class WaypointHelper {
}
@Override
public String getName() {
return OsmAndFormatter.getPoiSimpleFormat(a, app, app.getSettings().usingEnglishNames());
public String getName(Context ctx) {
return OsmAndFormatter.getPoiSimpleFormat(a, ctx, app.getSettings().usingEnglishNames());
}
@Override
@ -618,41 +634,9 @@ public class WaypointHelper {
}
}
private class TargetPointHelper implements LocationPoint {
private TargetPoint a;
public TargetPointHelper(TargetPoint a) {
this.a = a;
}
@Override
public double getLatitude() {
return a.point.getLatitude();
}
@Override
public double getLongitude() {
return a.point.getLongitude();
}
@Override
public String getName() {
return a.getVisibleName(app);
}
@Override
public int getColor() {
return 0;
}
@Override
public boolean isVisible() {
return false;
}
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.routing;
import android.content.Context;
import net.osmand.Location;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.data.LocationPoint;
@ -118,7 +119,7 @@ public class AlarmInfo implements LocationPoint {
}
@Override
public String getName() {
public String getName(Context ctx) {
return type.name();
}

View file

@ -870,7 +870,7 @@ public class RouteCalculationResult {
public int getIndexOfIntermediate(int countFromLast) {
final int j = intermediatePoints.length - countFromLast - 1;
if(j < intermediatePoints.length) {
if(j < intermediatePoints.length && j >= 0) {
int i = intermediatePoints[j];
return directions.get(i).routePointOffset;
}

View file

@ -94,6 +94,10 @@ public class RoutingHelper {
return isFollowingMode;
}
public OsmandApplication getApplication() {
return app;
}
public void setPauseNaviation(boolean b) {
this.isPauseNavigation = b;
}
@ -135,6 +139,7 @@ public class RoutingHelper {
route = new RouteCalculationResult("");
isDeviatedFromRoute = false;
evalWaitInterval = 3000;
app.getWaypointHelper().setNewRoute(route);
app.runInUIThread(new Runnable() {
@Override
public void run() {

View file

@ -288,7 +288,7 @@ public class VoiceRouter {
} else {
text += ", ";
}
text += point.getName();
text += point.getName(router.getApplication());
}
return text;
}

View file

@ -20,6 +20,7 @@ import net.osmand.util.Algorithms;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
@ -300,6 +301,10 @@ public class TourInformation {
return location.getLongitude();
}
public String getName(Context ctx) {
return name;
}
public String getName() {
return name;
}

View file

@ -151,7 +151,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
if (i++ > 0) {
res.append("\n\n");
}
res.append(getObjName() + " : " + fav.getName()); //$NON-NLS-1$
res.append(getObjName() + " : " + fav.getName(view.getContext())); //$NON-NLS-1$
}
AccessibleToast.makeText(view.getContext(), res.toString(), Toast.LENGTH_LONG).show();
return true;
@ -164,7 +164,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
public String getObjectDescription(Object o) {
Class<? extends LocationPoint> fcl = getFavoriteClass();
if(o!= null && fcl.isInstance(o)) {
return getObjName() + " : " + ((LocationPoint)o).getName(); //$NON-NLS-1$
return getObjName() + " : " + ((LocationPoint)o).getName(view.getContext()); //$NON-NLS-1$
}
return null;
}
@ -174,7 +174,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override
public String getObjectName(Object o) {
if(o instanceof LocationPoint){
return ((LocationPoint)o).getName(); //$NON-NLS-1$
return ((LocationPoint)o).getName(view.getContext()); //$NON-NLS-1$
}
return null;
}
@ -233,7 +233,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override
public String getText(LocationPoint o) {
return o.getName();
return o.getName(view.getContext());
}