Fixes: Display Starting point always. Show sort and switch start/destination changes immediately. Added Starting point icon. Other small issues.

This commit is contained in:
Alexey Kulish 2016-01-21 17:03:45 +03:00
parent 2e3c0e3f19
commit f12ae8c1b0
8 changed files with 153 additions and 90 deletions

View file

@ -229,6 +229,18 @@ public class TargetPointsHelper {
return intermediatePointsLatLon;
}
public List<TargetPoint> getAllPoints() {
List<TargetPoint> res = new ArrayList<TargetPoint>();
if(pointToStart != null) {
res.add(pointToStart);
}
res.addAll(this.intermediatePoints);
if(pointToNavigate != null) {
res.add(pointToNavigate);
}
return res;
}
public List<TargetPoint> getIntermediatePointsWithTarget() {
List<TargetPoint> res = new ArrayList<TargetPoint>();
res.addAll(this.intermediatePoints);

View file

@ -54,7 +54,7 @@ import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointDialogHelper.PointDeleteCallback;
import net.osmand.plus.helpers.WaypointDialogHelper.WaypointDialogHelperCallbacks;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.LocalRoutingParameter;
@ -81,7 +81,7 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
/**
*/
public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicListViewCallbacks,
IRouteInformationListener, PointDeleteCallback {
IRouteInformationListener, WaypointDialogHelperCallbacks {
private static final org.apache.commons.logging.Log LOG =
PlatformUtil.getLog(DashboardOnMap.class);
private static final String TAG = "DashboardOnMap";
@ -179,7 +179,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
public void createDashboardView() {
baseColor = mapActivity.getResources().getColor(R.color.osmand_orange) & 0x00ffffff;
waypointDialogHelper = new WaypointDialogHelper(mapActivity);
waypointDialogHelper.setPointDeleteCallback(this);
waypointDialogHelper.setWaypointDialogHelperCallbacks(this);
landscape = !AndroidUiHelper.isOrientationPortrait(mapActivity);
dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard);
final View.OnClickListener listener = new View.OnClickListener() {
@ -1212,16 +1212,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
@Override
public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToast) {
if ((DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType)
&& listAdapter != null && listAdapter instanceof StableArrayAdapter) {
StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
waypointDialogHelper.reloadListAdapter(stableAdapter);
if (listView instanceof DynamicListView) {
DynamicListView dynamicListView = (DynamicListView) listView;
dynamicListView.setItemsList(stableAdapter.getObjects());
dynamicListView.setActiveItemsList(stableAdapter.getActiveObjects());
}
}
reloadAdapter();
showToast.value = false;
}
@ -1236,6 +1227,20 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
}
}
@Override
public void reloadAdapter() {
if ((DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType)
&& listAdapter != null && listAdapter instanceof StableArrayAdapter) {
StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
waypointDialogHelper.reloadListAdapter(stableAdapter);
if (listView instanceof DynamicListView) {
DynamicListView dynamicListView = (DynamicListView) listView;
dynamicListView.setItemsList(stableAdapter.getObjects());
dynamicListView.setActiveItemsList(stableAdapter.getActiveObjects());
}
}
}
@Override
public void deleteWaypoint(int position) {
if (swipeDismissListener != null) {

View file

@ -55,12 +55,13 @@ public class WaypointDialogHelper {
private MapActivity mapActivity;
private OsmandApplication app;
private WaypointHelper waypointHelper;
private PointDeleteCallback dCallback;
private WaypointDialogHelperCallbacks helperCallbacks;
private boolean flat;
private List<LocationPointWrapper> deletedPoints;
public interface PointDeleteCallback {
public interface WaypointDialogHelperCallbacks {
void reloadAdapter();
void deleteWaypoint(int position);
}
@ -72,8 +73,8 @@ public class WaypointDialogHelper {
}
}
public void setPointDeleteCallback(PointDeleteCallback callback) {
this.dCallback = callback;
public void setWaypointDialogHelperCallbacks(WaypointDialogHelperCallbacks callbacks) {
this.helperCallbacks = callbacks;
}
public WaypointDialogHelper(MapActivity mapActivity) {
@ -354,7 +355,11 @@ public class WaypointDialogHelper {
= new GeocodingLookupService.AddressLookupRequest(t.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
reloadListAdapter(listAdapter);
if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
}
}, null);
app.getGeocodingLookupService().lookupAddress(lookupRequest);
@ -395,46 +400,58 @@ public class WaypointDialogHelper {
more.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean hasActivePoints = false;
if (adapter instanceof StableArrayAdapter) {
hasActivePoints = ((StableArrayAdapter) adapter).getActiveObjects().size() > 0;
}
final PopupMenu optionsMenu = new PopupMenu(ctx, more);
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
MenuItem item;
item = optionsMenu.getMenu().add(
R.string.intermediate_items_sort_by_distance).setIcon(app.getIconsCache().
getContentIcon(R.drawable.ic_sort_waypoint_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// sort door-to-door
sortAllTargets(app, ctx);
return true;
}
});
item = optionsMenu.getMenu().add(
R.string.switch_start_finish).setIcon(app.getIconsCache().
getContentIcon(R.drawable.ic_action_undo_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// switch start & finish
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint start = targetPointsHelper.getPointToStart();
TargetPoint finish = targetPointsHelper.getPointToNavigate();
targetPointsHelper.setStartPoint(new LatLon(finish.getLatitude(),
finish.getLongitude()), false, finish.getPointDescription(ctx));
if (start == null) {
Location loc = app.getLocationProvider().getLastKnownLocation();
if (loc != null) {
targetPointsHelper.navigateToPoint(new LatLon(loc.getLatitude(),
loc.getLongitude()), true, -1);
}
} else {
targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(),
start.getLongitude()), true, -1, start.getPointDescription(ctx));
if (hasActivePoints) {
item = optionsMenu.getMenu().add(
R.string.intermediate_items_sort_by_distance).setIcon(app.getIconsCache().
getContentIcon(R.drawable.ic_sort_waypoint_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// sort door-to-door
sortAllTargets(app, ctx, helper);
return true;
}
return true;
}
});
optionsMenu.show();
});
item = optionsMenu.getMenu().add(
R.string.switch_start_finish).setIcon(app.getIconsCache().
getContentIcon(R.drawable.ic_action_undo_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// switch start & finish
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
TargetPoint start = targetPointsHelper.getPointToStart();
TargetPoint finish = targetPointsHelper.getPointToNavigate();
targetPointsHelper.setStartPoint(new LatLon(finish.getLatitude(),
finish.getLongitude()), false, finish.getPointDescription(ctx));
if (start == null) {
Location loc = app.getLocationProvider().getLastKnownLocation();
if (loc != null) {
targetPointsHelper.navigateToPoint(new LatLon(loc.getLatitude(),
loc.getLongitude()), true, -1);
}
} else {
targetPointsHelper.navigateToPoint(new LatLon(start.getLatitude(),
start.getLongitude()), true, -1, start.getPointDescription(ctx));
}
if (helper.helperCallbacks != null) {
helper.helperCallbacks.reloadAdapter();
}
return true;
}
});
}
if (optionsMenu.getMenu().size() > 0) {
optionsMenu.show();
}
}
});
} else {
@ -489,8 +506,8 @@ public class WaypointDialogHelper {
LocationPointWrapper point = (LocationPointWrapper) item;
if (point.type == WaypointHelper.TARGETS && adapter instanceof StableArrayAdapter) {
StableArrayAdapter stableAdapter = (StableArrayAdapter) adapter;
if (helper != null && helper.dCallback != null && needCallback) {
helper.dCallback.deleteWaypoint(stableAdapter.getPosition(item));
if (helper != null && helper.helperCallbacks != null && needCallback) {
helper.helperCallbacks.deleteWaypoint(stableAdapter.getPosition(item));
}
} else {
ArrayList<LocationPointWrapper> arr = new ArrayList<>();
@ -633,7 +650,11 @@ public class WaypointDialogHelper {
protected void onPostExecute(Void result) {
running[0] = -1;
reloadListAdapter(listAdapter);
if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
}
}.execute((Void) null);
}
@ -696,7 +717,11 @@ public class WaypointDialogHelper {
protected void onPostExecute(Void result) {
running[0] = -1;
reloadListAdapter(listAdapter);
if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
}
}.execute((Void) null);
}
@ -750,7 +775,7 @@ public class WaypointDialogHelper {
points.add(true);
}
points.add(i);
if (i == WaypointHelper.TARGETS && rc) {
if (i == WaypointHelper.TARGETS) {
TargetPoint start = app.getTargetPointsHelper().getPointToStart();
if (start == null) {
LatLon latLon;
@ -837,7 +862,8 @@ public class WaypointDialogHelper {
*/
}
public static void sortAllTargets(final OsmandApplication app, final Activity activity) {
public static void sortAllTargets(final OsmandApplication app, final Activity activity,
final WaypointDialogHelper helper) {
new AsyncTask<Void, Void, int[]>() {
@ -917,6 +943,9 @@ public class WaypointDialogHelper {
if (!eq) {
targets.reorderAllTargetPoints(intermediates, true);
}
if (helper.helperCallbacks != null) {
helper.helperCallbacks.reloadAdapter();
}
}
}.execute();

View file

@ -686,7 +686,7 @@ public class WaypointHelper {
ApplicationMode appMode = app.getSettings().getApplicationMode();
return uiCtx.getResources().getDrawable(appMode.getResourceLocationDay());
} else {
return iconsCache.getContentIcon(R.drawable.ic_action_marker_dark, !nightMode);
return iconsCache.getIcon(R.drawable.list_startpoint, 0, 0f);
}
} else if (((TargetPoint) point).intermediate) {
if (!nightMode) {

View file

@ -418,7 +418,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
hide();
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
if (targets.getIntermediatePoints().isEmpty()) {
targets.navigateToPoint(latLon, true, -1, pointDescription);
targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
} else {
Builder bld = new AlertDialog.Builder(mapActivity);
@ -439,10 +439,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void onClick(DialogInterface dialog, int which) {
if (defaultVls[0] == 0) {
targets.removeAllWayPoints(false);
targets.navigateToPoint(latLon, true, -1, pointDescription);
targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
} else {
targets.navigateToPoint(latLon, true, -1, pointDescription);
targets.navigateToPoint(latLon, true, -1, getPointDescriptionForTarget());
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true);
}
}
@ -457,7 +457,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
mapActivity.getMapActions().editWaypoints();
} else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
pointDescription);
getPointDescriptionForTarget());
}
close();
}
@ -518,7 +518,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
public void addAsLastIntermediate() {
mapActivity.getMyApplication().getTargetPointsHelper().navigateToPoint(latLon,
true, mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size(),
pointDescription);
getPointDescriptionForTarget());
close();
}
@ -562,6 +562,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
return GpxUiHelper.selectSingleGPXFile(mapActivity, true, callbackWithObject);
}
private PointDescription getPointDescriptionForTarget() {
if (pointDescription.isLocation()
&& pointDescription.getName().equals(PointDescription.getAddressNotFoundStr(mapActivity))) {
return new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
} else {
return pointDescription;
}
}
public void setBaseFragmentVisibility(boolean visible) {
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null) {

View file

@ -24,27 +24,29 @@ public class TargetPointMenuController extends MenuController {
final int intermediatePointsCount = targetPointsHelper.getIntermediatePoints().size();
RoutingHelper routingHelper = getMapActivity().getMyApplication().getRoutingHelper();
final boolean nav = routingHelper.isRoutePlanningMode() || routingHelper.isFollowingMode();
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
TargetPoint tp = getTargetPoint();
if(tp.intermediate) {
targetPointsHelper.removeWayPoint(true, tp.index);
} else {
targetPointsHelper.removeWayPoint(true, -1);
}
getMapActivity().getContextMenu().close();
if (nav && intermediatePointsCount == 0) {
getMapActivity().getMapActions().stopNavigationWithoutConfirm();
if (!targetPoint.start) {
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
TargetPoint tp = getTargetPoint();
if (tp.intermediate) {
targetPointsHelper.removeWayPoint(true, tp.index);
} else {
targetPointsHelper.removeWayPoint(true, -1);
}
getMapActivity().getContextMenu().close();
if (nav && intermediatePointsCount == 0) {
getMapActivity().getMapActions().stopNavigationWithoutConfirm();
}
}
};
if (nav && intermediatePointsCount == 0) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.cancel_navigation);
leftTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark;
} else {
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_remove);
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
}
};
if (nav && intermediatePointsCount == 0) {
leftTitleButtonController.caption = getMapActivity().getString(R.string.cancel_navigation);
leftTitleButtonController.leftIconId = R.drawable.ic_action_remove_dark;
} else {
leftTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_remove);
leftTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark;
}
}
@ -76,7 +78,9 @@ public class TargetPointMenuController extends MenuController {
@Override
public Drawable getLeftIcon() {
if (!targetPoint.intermediate) {
if (targetPoint.start) {
return getIconOrig(R.drawable.list_startpoint);
} else if (!targetPoint.intermediate) {
if (isLight()) {
return getIconOrig(R.drawable.widget_target_day);
} else {
@ -93,7 +97,11 @@ public class TargetPointMenuController extends MenuController {
@Override
public String getTypeStr() {
return targetPoint.getPointDescription(getMapActivity()).getTypeName();
if (targetPoint.start) {
return getMapActivity().getString(R.string.starting_point);
} else {
return targetPoint.getPointDescription(getMapActivity()).getTypeName();
}
}
@Override

View file

@ -340,7 +340,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
ApplicationMode appMode = mapActivity.getMyApplication().getSettings().getApplicationMode();
fromIcon.setImageDrawable(mapActivity.getResources().getDrawable(appMode.getResourceLocationDay()));
} else {
fromIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_marker_dark, isLight()));
fromIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.list_startpoint, 0, 0f));
}
}

View file

@ -60,7 +60,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
textPaint.setTextSize(sp * 18);
textPaint.setTextAlign(Align.CENTER);
textPaint.setAntiAlias(true);
startPoint = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_intermediate_point);
startPoint = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_start_point);
targetPoint = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_target_point);
intermediatePoint = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_intermediate_point);
arrowToDestination = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_arrow_to_destination);
@ -175,7 +175,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper();
List<TargetPoint> intermediatePoints = tg.getIntermediatePointsWithTarget();
List<TargetPoint> intermediatePoints = tg.getAllPoints();
int r = getRadiusPoi(tileBox);
for (int i = 0; i < intermediatePoints.size(); i++) {
TargetPoint tp = intermediatePoints.get(i);