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_marginRight="2dp"
android:paddingLeft="10dp"
android:paddingRight="20dp"
android:paddingRight="10dp"
android:gravity="left|center_vertical"
android:text="@string/osmand_parking_delete"
android:background="?android:selectableItemBackground"

View file

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

View file

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

View file

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

View file

@ -29,6 +29,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -124,8 +125,8 @@ public class ParkingPositionPlugin extends OsmandPlugin {
}
public boolean setParkingPosition(double latitude, double longitude) {
parkingLat.set((float)latitude);
parkingLon.set((float)longitude);
parkingLat.set((float) latitude);
parkingLon.set((float) longitude);
parkingPosition = constructParkingPosition();
return true;
}
@ -210,21 +211,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
public void registerMapContextMenuActions(final MapActivity mapActivity,
final double latitude, final double longitude,
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() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId,
@ -295,12 +282,12 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override
public void onClick(DialogInterface dialog, int which) {
showDeleteEventWarning(activity);
if(parkingLayer != null) {
if (parkingLayer != null) {
parkingLayer.refresh();
}
clearParkingPosition();
if (activity instanceof MapActivity){
((MapActivity)activity).getMapView().refreshMap();
if (activity instanceof MapActivity) {
((MapActivity) activity).getContextMenu().close();
}
}
});
@ -365,8 +352,8 @@ public class ParkingPositionPlugin extends OsmandPlugin {
Calendar cal = Calendar.getInstance();
//int hour = cal.get(Calendar.HOUR_OF_DAY );
//int minute = cal.get(Calendar.MINUTE);
cal.add(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
cal.add(Calendar.MINUTE, timePicker.getCurrentMinute());
cal.add(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
cal.add(Calendar.MINUTE, timePicker.getCurrentMinute());
setParkingTime(cal.getTimeInMillis());
CheckBox addCalendarEvent = (CheckBox) setTimeParking.findViewById(R.id.check_event_in_calendar);
if (addCalendarEvent.isChecked()) {
@ -391,7 +378,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
intent.putExtra("calendar_id", 1); //$NON-NLS-1$
intent.putExtra("title", view.getContext().getString(R.string.osmand_parking_event)); //$NON-NLS-1$
intent.putExtra("beginTime", getParkingTime()); //$NON-NLS-1$
intent.putExtra("endTime", getParkingTime()+60*60*1000); //$NON-NLS-1$
intent.putExtra("endTime", getParkingTime() + 60 * 60 * 1000); //$NON-NLS-1$
view.getContext().startActivity(intent);
}
@ -426,6 +413,10 @@ public class ParkingPositionPlugin extends OsmandPlugin {
setParkingType(isLimited);
setParkingStartTime(Calendar.getInstance().getTimeInMillis());
if (parkingLayer != null) {
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isVisible()) {
menu.show(new LatLon(latitude, longitude), parkingLayer.getObjectName(parkingPosition), parkingPosition);
}
parkingLayer.refresh();
}
}
@ -539,6 +530,50 @@ public class ParkingPositionPlugin extends OsmandPlugin {
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) {
StringBuilder timeLimitDesc = new StringBuilder();
timeLimitDesc.append(ctx.getString(R.string.osmand_parking_position_description_add_time) + " ");