Added parking context menu

This commit is contained in:
Alexey Kulish 2015-10-23 15:28:35 +03:00
parent 6af5a71028
commit e3063b462d
5 changed files with 96 additions and 32 deletions

View file

@ -88,7 +88,7 @@
android:layout_marginLeft="2dp" android:layout_marginLeft="2dp"
android:layout_marginRight="2dp" android:layout_marginRight="2dp"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="20dp" android:paddingRight="10dp"
android:gravity="left|center_vertical" android:gravity="left|center_vertical"
android:text="@string/osmand_parking_delete" android:text="@string/osmand_parking_delete"
android:background="?android:selectableItemBackground" android:background="?android:selectableItemBackground"

View file

@ -220,15 +220,15 @@ public class MapContextMenu {
menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object); menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object);
} else if (object instanceof HistoryEntry) { } else if (object instanceof HistoryEntry) {
menuController = new HistoryMenuController(app, mapActivity, (HistoryEntry) object); menuController = new HistoryMenuController(app, mapActivity, (HistoryEntry) object);
} } else if (object instanceof LatLon) {
} else {
if (pointDescription.isParking()) { if (pointDescription.isParking()) {
menuController = new ParkingPositionController(app, mapActivity, pointDescription, latLon); menuController = new ParkingPositionController(app, mapActivity, pointDescription, latLon);
}
}
} else { } else {
menuController = new PointDescriptionMenuController(app, mapActivity, pointDescription, latLon); menuController = new PointDescriptionMenuController(app, mapActivity, pointDescription, latLon);
} }
} }
}
public void onSingleTapOnMap() { public void onSingleTapOnMap() {
if (menuController == null || !menuController.handleSingleTapOnMap()) { if (menuController == null || !menuController.handleSingleTapOnMap()) {
@ -540,6 +540,8 @@ public class MapContextMenu {
} }
public void titleButtonPressed() { public void titleButtonPressed() {
if (menuController != null) {
menuController.titleButtonPressed();
}
} }
} }

View file

@ -153,6 +153,9 @@ public abstract class MenuController {
return ""; return "";
} }
public void titleButtonPressed() {
}
public boolean shouldShowButtons() { public boolean shouldShowButtons() {
return true; return true;
} }

View file

@ -2,24 +2,41 @@ package net.osmand.plus.mapcontextmenu.details;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.widget.ArrayAdapter;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchHistoryFragment; import net.osmand.plus.activities.search.SearchHistoryFragment;
import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.util.Algorithms;
public class ParkingPositionController extends MenuController { public class ParkingPositionController extends MenuController {
private PointDescription pointDescription; private PointDescription pointDescription;
private LatLon latLon; private LatLon latLon;
ParkingPositionPlugin plugin;
String parkingDescription = "";
public ParkingPositionController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) { public ParkingPositionController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) {
super(new ParkingPositionBuilder(app), mapActivity); super(new ParkingPositionBuilder(app), mapActivity);
this.pointDescription = pointDescription; this.pointDescription = pointDescription;
this.latLon = latLon; this.latLon = latLon;
plugin = OsmandPlugin.getPlugin(ParkingPositionPlugin.class);
if (plugin != null) {
StringBuilder sb = new StringBuilder();
sb.append(plugin.getParkingStartDesc(mapActivity));
String leftDesc = plugin.getParkingLeftDesc(mapActivity);
if (!Algorithms.isEmpty(leftDesc)) {
sb.append("\n").append(leftDesc);
}
parkingDescription = sb.toString();
}
} }
@Override @Override
@ -34,7 +51,7 @@ public class ParkingPositionController extends MenuController {
@Override @Override
public boolean needTypeStr() { public boolean needTypeStr() {
return true; return !Algorithms.isEmpty(parkingDescription);
} }
@Override @Override
@ -49,7 +66,7 @@ public class ParkingPositionController extends MenuController {
@Override @Override
public String getTypeStr() { public String getTypeStr() {
return "Parked at 10:23"; return parkingDescription;
} }
@Override @Override
@ -62,6 +79,13 @@ public class ParkingPositionController extends MenuController {
return getMapActivity().getText(R.string.osmand_parking_delete).toString(); return getMapActivity().getText(R.string.osmand_parking_delete).toString();
} }
@Override
public void titleButtonPressed() {
if (plugin != null) {
plugin.showDeleteDialog(getMapActivity());
}
}
@Override @Override
public boolean needStreetName() { public boolean needStreetName() {
return false; return false;

View file

@ -29,6 +29,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -210,20 +211,6 @@ public class ParkingPositionPlugin extends OsmandPlugin {
public void registerMapContextMenuActions(final MapActivity mapActivity, public void registerMapContextMenuActions(final MapActivity mapActivity,
final double latitude, final double longitude, final double latitude, final double longitude,
ContextMenuAdapter adapter, Object selectedObj) { ContextMenuAdapter adapter, Object selectedObj) {
if (selectedObj == parkingPosition && parkingPosition != null) {
OnContextMenuClick removeListener = new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId,
int pos, boolean isChecked) {
if ((resId == R.string.context_menu_item_delete_parking_point)) {
showDeleteDialog(mapActivity);
}
return true;
}
};
adapter.item(R.string.context_menu_item_delete_parking_point)
.iconColor( R.drawable.ic_action_remove_dark).listen(removeListener).position(0).reg();
}
OnContextMenuClick addListener = new OnContextMenuClick() { OnContextMenuClick addListener = new OnContextMenuClick() {
@Override @Override
@ -300,7 +287,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
} }
clearParkingPosition(); clearParkingPosition();
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
((MapActivity)activity).getMapView().refreshMap(); ((MapActivity) activity).getContextMenu().close();
} }
} }
}); });
@ -426,6 +413,10 @@ public class ParkingPositionPlugin extends OsmandPlugin {
setParkingType(isLimited); setParkingType(isLimited);
setParkingStartTime(Calendar.getInstance().getTimeInMillis()); setParkingStartTime(Calendar.getInstance().getTimeInMillis());
if (parkingLayer != null) { if (parkingLayer != null) {
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isVisible()) {
menu.show(new LatLon(latitude, longitude), parkingLayer.getObjectName(parkingPosition), parkingPosition);
}
parkingLayer.refresh(); parkingLayer.refresh();
} }
} }
@ -539,6 +530,50 @@ public class ParkingPositionPlugin extends OsmandPlugin {
return timeStringBuilder.toString(); return timeStringBuilder.toString();
} }
String getFormattedTimeInterval(long timeInMillis, Activity ctx) {
if (timeInMillis < 0) {
timeInMillis *= -1;
}
StringBuilder timeStringBuilder = new StringBuilder();
int hours = (int) timeInMillis / (1000 * 60 * 60);
int minMills = (int) timeInMillis % (1000 * 60 * 60);
int minutes = minMills / (1000 * 60);
if (hours > 0) {
timeStringBuilder.append(hours);
timeStringBuilder.append(" ");
timeStringBuilder.append(ctx.getString(R.string.osmand_parking_hour));
}
timeStringBuilder.append(" ");
timeStringBuilder.append(minutes);
timeStringBuilder.append(" ");
timeStringBuilder.append(ctx.getString(R.string.osmand_parking_minute));
return timeStringBuilder.toString();
}
public String getParkingStartDesc(Activity ctx) {
return ctx.getString(R.string.osmand_parking_position_description_add_time)
+ " " + getFormattedTime(getStartParkingTime(), ctx);
}
public String getParkingLeftDesc(Activity ctx) {
StringBuilder descr = new StringBuilder();
if (getParkingType()) {
long endtime = getParkingTime();
long currTime = Calendar.getInstance().getTimeInMillis();
long timeDiff = endtime - currTime;
descr.append(getFormattedTimeInterval(timeDiff, ctx)).append(" ");
if (timeDiff < 0) {
descr.append(ctx.getString(R.string.osmand_parking_overdue));
} else {
descr.append(ctx.getString(R.string.osmand_parking_time_left));
}
}
return descr.toString();
}
public String getParkingDescription(Activity ctx) { public String getParkingDescription(Activity ctx) {
StringBuilder timeLimitDesc = new StringBuilder(); StringBuilder timeLimitDesc = new StringBuilder();
timeLimitDesc.append(ctx.getString(R.string.osmand_parking_position_description_add_time) + " "); timeLimitDesc.append(ctx.getString(R.string.osmand_parking_position_description_add_time) + " ");