Delete ParkingPositionLayer

This commit is contained in:
Dima-1 2020-01-21 17:51:45 +02:00
parent f55e4f7c00
commit 32783e61cd
5 changed files with 61 additions and 296 deletions

View file

@ -87,12 +87,24 @@ public class FavoriteImageDrawable extends Drawable {
@Override
public int getIntrinsicHeight() {
return synced ? syncedShadow.getHeight() : special ? favIcon.getHeight() : favBackground.getHeight();
if (synced) {
return syncedShadow.getHeight();
}
if (special) {
return favIcon.getHeight();
}
return favBackground.getHeight();
}
@Override
public int getIntrinsicWidth() {
return synced ? syncedShadow.getWidth() : special ? favIcon.getWidth() : favBackground.getWidth();
if (synced) {
return syncedShadow.getWidth();
}
if (special) {
return favIcon.getWidth();
}
return favBackground.getWidth();
}
@Override

View file

@ -101,7 +101,7 @@ public class DashParkingFragment extends DashLocationFragment {
TextView timeLeft = (TextView) mainView.findViewById(R.id.time_left);
if (limited) {
descr = getString(R.string.parking_place_limited) + " " + plugin.getFormattedTime( plugin.getParkingTime(), getActivity());
descr = getString(R.string.parking_place_limited) + " " + plugin.getFormattedTime( plugin.getParkingTime());
long endtime = plugin.getParkingTime();
long currTime = Calendar.getInstance().getTimeInMillis();
long timeDiff = endtime - currTime;

View file

@ -1,226 +0,0 @@
package net.osmand.plus.parkingpoint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView;
import java.util.List;
/**
* Class represents a layer which depicts the position of the parked car
* @author Alena Fedasenka
* @see ParkingPositionPlugin
*
*/
public class ParkingPositionLayer extends OsmandMapLayer implements
ContextMenuLayer.IContextMenuProvider, ContextMenuLayer.IMoveObjectProvider {
/**
* magic number so far
*/
private static final int radius = 18;
private DisplayMetrics dm;
private final MapActivity map;
private OsmandMapTileView view;
private Paint bitmapPaint;
private Bitmap parkingNoLimitIcon;
private Bitmap parkingLimitIcon;
private boolean timeLimit;
private ParkingPositionPlugin plugin;
private ContextMenuLayer contextMenuLayer;
public ParkingPositionLayer(MapActivity map, ParkingPositionPlugin plugin) {
this.map = map;
this.plugin = plugin;
}
public LatLon getParkingPoint() {
return plugin.getParkingPosition();
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm);
bitmapPaint = new Paint();
bitmapPaint.setDither(true);
bitmapPaint.setAntiAlias(true);
bitmapPaint.setFilterBitmap(true);
parkingNoLimitIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_poi_parking_pos_no_limit);
parkingLimitIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_poi_parking_pos_limit);
timeLimit = plugin.getParkingType();
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
LatLon parkingPoint = getParkingPoint();
boolean inMotion = parkingPoint == contextMenuLayer.getMoveableObject();
if (parkingPoint == null)
return;
Bitmap parkingIcon;
if (!timeLimit) {
parkingIcon = parkingNoLimitIcon;
} else {
parkingIcon = parkingLimitIcon;
}
double latitude = parkingPoint.getLatitude();
double longitude = parkingPoint.getLongitude();
if (isLocationVisible(tileBox, latitude, longitude) || inMotion) {
int marginX = parkingNoLimitIcon.getWidth() / 2;
int marginY = parkingNoLimitIcon.getHeight() / 2;
float locationX;
float locationY;
if (inMotion) {
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
locationX = pf.x;
locationY = pf.y;
} else {
locationX = tileBox.getPixXFromLonNoRot(longitude);
locationY = tileBox.getPixYFromLatNoRot(latitude);
}
canvas.rotate(-view.getRotate(), locationX, locationY);
canvas.drawBitmap(parkingIcon, locationX - marginX, locationY - marginY, bitmapPaint);
}
}
@Override
public void destroyLayer() {
}
@Override
public boolean drawInScreenPixels() {
return false;
}
@Override
public boolean disableSingleTap() {
return false;
}
@Override
public boolean disableLongPressOnMap() {
return false;
}
@Override
public boolean isObjectClickable(Object o) {
return o == getParkingPoint();
}
@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
getParkingFromPoint(tileBox, point, o);
}
@Override
public LatLon getObjectLocation(Object o) {
if(o == getParkingPoint()) {
return getParkingPoint();
}
return null;
}
public String getFormattedTime(long time){
return plugin.getFormattedTime(time, map);
}
@Override
public PointDescription getObjectName(Object o) {
return new PointDescription(PointDescription.POINT_TYPE_PARKING_MARKER,
view.getContext().getString(R.string.osmand_parking_position_name));
}
public void refresh() {
if (view != null) {
view.refreshMap();
}
}
/**
* @param latitude
* @param longitude
* @return true if the parking point is located on a visible part of map
*/
private boolean isLocationVisible(RotatedTileBox tb, double latitude, double longitude){
if(getParkingPoint() == null || view == null){
return false;
}
return tb.containsLatLon(latitude, longitude);
}
/**
* @param point
* @param parkingPosition
* is in this case not necessarily has to be a list, but it's also used in method
* <link>collectObjectsFromPoint(PointF point, List<Object> o)</link>
*/
private void getParkingFromPoint(RotatedTileBox tb, PointF point, List<? super LatLon> parkingPosition) {
LatLon parkingPoint = getParkingPoint();
if (parkingPoint != null && view != null) {
int ex = (int) point.x;
int ey = (int) point.y;
LatLon position = plugin.getParkingPosition();
int x = (int) tb.getPixXFromLatLon(position.getLatitude(), position.getLongitude());
int y = (int) tb.getPixYFromLatLon(position.getLatitude(), position.getLongitude());
// the width of an image is 40 px, the height is 60 px -> radius = 20,
// the position of a parking point relatively to the icon is at the center of the bottom line of the image
int rad = (int) (radius * tb.getDensity());
if (Math.abs(x - ex) <= rad && (ey - y) <= rad && (y - ey) <= 2.5 * rad) {
parkingPosition.add(parkingPoint);
}
}
}
@Override
public boolean isObjectMovable(Object o) {
return o == getParkingPoint();
}
@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position,
@Nullable ContextMenuLayer.ApplyMovedObjectCallback callback) {
boolean result = false;
if (o == getParkingPoint()) {
plugin.setParkingPosition(position.getLatitude(), position.getLongitude());
result = true;
}
if (callback != null) {
callback.onApplyMovedObject(result, getParkingPoint());
}
}
}

View file

@ -17,6 +17,7 @@ import android.widget.TimePicker;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
@ -61,10 +62,9 @@ public class ParkingPositionPlugin extends OsmandPlugin {
// Constants for determining the order of items in the additional actions context menu
private static final int MARK_AS_PARKING_POS_ITEM_ORDER = 10500;
private LatLon parkingPosition;
private OsmandApplication app;
private LatLon parkingPosition;
private OsmandApplication app;
private ParkingPositionLayer parkingLayer;
private TextInfoWidget parkingPlaceControl;
private final CommonPreference<Float> parkingLat;
private final CommonPreference<Float> parkingLon;
@ -83,13 +83,12 @@ public class ParkingPositionPlugin extends OsmandPlugin {
parkingEvent = set.registerBooleanPreference(PARKING_EVENT_ADDED, false).makeGlobal();
parkingTime = set.registerLongPreference(PARKING_TIME, -1).makeGlobal();
parkingStartTime = set.registerLongPreference(PARKING_START_TIME, -1).makeGlobal();
parkingPosition = constructParkingPosition();
parkingPosition = constructParkingPosition();
}
public LatLon getParkingPosition() {
return parkingPosition;
}
public LatLon getParkingPosition() {
return parkingPosition;
}
public LatLon constructParkingPosition() {
float lat = parkingLat.get();
@ -127,7 +126,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
parkingTime.resetToDefault();
parkingEvent.resetToDefault();
parkingStartTime.resetToDefault();
parkingPosition = null;
parkingPosition = null;
return true;
}
@ -187,29 +186,16 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override
public void registerLayers(MapActivity activity) {
// remove old if existing after turn
if(parkingLayer != null) {
activity.getMapView().removeLayer(parkingLayer);
}
parkingLayer = new ParkingPositionLayer(activity, this);
// activity.getMapView().addLayer(parkingLayer, 5.5f);
registerWidget(activity);
}
@Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
if (isActive()) {
if (parkingLayer == null) {
registerLayers(activity);
}
if (parkingPlaceControl == null) {
registerWidget(activity);
}
} else {
if (parkingLayer != null) {
activity.getMapView().removeLayer(parkingLayer);
parkingLayer = null;
}
MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
if (mapInfoLayer != null && parkingPlaceControl != null) {
mapInfoLayer.removeSideWidget(parkingPlaceControl);
@ -269,16 +255,18 @@ public class ParkingPositionPlugin extends OsmandPlugin {
}
void showContextMenuIfNeeded(final MapActivity mapActivity, boolean animated) {
if (parkingLayer != null) {
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isVisible()) {
menu.hide(animated);
menu.show(new LatLon(parkingPosition.getLatitude(), parkingPosition.getLongitude()),
parkingLayer.getObjectName(parkingPosition), parkingPosition);
}
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isVisible()) {
menu.hide(animated);
menu.show(new LatLon(parkingPosition.getLatitude(), parkingPosition.getLongitude()),
getObjectName(parkingPosition), parkingPosition);
}
}
public PointDescription getObjectName(Object o) {
return new PointDescription(PointDescription.POINT_TYPE_PARKING_MARKER,
app.getString(R.string.osmand_parking_position_name));
}
/**
* Method creates confirmation dialog for deletion of a parking location.
*/
@ -335,25 +323,25 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override
public void onTimeChanged(TimePicker timePicker, int hourOfDay, int minute) {
if (mIgnoreEvent) {
return;
}
if (minute % TIME_PICKER_INTERVAL != 0) {
int minuteFloor = minute - (minute % TIME_PICKER_INTERVAL);
minute = minuteFloor + (minute == minuteFloor + 1 ? TIME_PICKER_INTERVAL : 0);
if (minute == 60) {
minute = 0;
}
mIgnoreEvent = true;
timePicker.setCurrentMinute(minute);
mIgnoreEvent = false;
}
long timeInMillis = cal.getTimeInMillis() + hourOfDay * 60 * 60 * 1000 + minute * 60 * 1000;
textView.setText(mapActivity.getString(R.string.osmand_parking_position_description_add)
+ " " + parkingLayer.getFormattedTime(timeInMillis));
if (mIgnoreEvent) {
return;
}
if (minute % TIME_PICKER_INTERVAL != 0) {
int minuteFloor = minute - (minute % TIME_PICKER_INTERVAL);
minute = minuteFloor + (minute == minuteFloor + 1 ? TIME_PICKER_INTERVAL : 0);
if (minute == 60) {
minute = 0;
}
mIgnoreEvent = true;
timePicker.setCurrentMinute(minute);
mIgnoreEvent = false;
}
long timeInMillis = cal.getTimeInMillis() + hourOfDay * 60 * 60 * 1000 + minute * 60 * 1000;
textView.setText(mapActivity.getString(R.string.osmand_parking_position_description_add)
+ " " + getFormattedTime(timeInMillis));
}
});
}
});
//to set the same 24-hour or 12-hour mode as it is set in the device
@ -420,24 +408,17 @@ public class ParkingPositionPlugin extends OsmandPlugin {
/**
* Method sets a parking point on a ParkingLayer.
* @param mapActivity
* @param latitude
* @param longitude
* @param isLimited
*/
void setParkingPosition(final MapActivity mapActivity, final double latitude, final double longitude, boolean isLimited) {
void setParkingPosition(final double latitude, final double longitude, boolean isLimited) {
setParkingPosition(latitude, longitude);
setParkingType(isLimited);
setParkingStartTime(Calendar.getInstance().getTimeInMillis());
if (parkingLayer != null) {
parkingLayer.refresh();
}
}
private void cancelParking() {
if (parkingLayer != null) {
parkingLayer.refresh();
}
clearParkingPosition();
}
@ -454,8 +435,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override
public boolean updateInfo(DrawSettings drawSettings) {
if (parkingLayer != null) {
LatLon parkingPoint = parkingLayer.getParkingPoint();
LatLon parkingPoint = getParkingPosition();
if (parkingPoint != null && !map.getRoutingHelper().isFollowingMode()) {
OsmandMapTileView view = map.getMapView();
int d = 0;
@ -484,7 +464,6 @@ public class ParkingPositionPlugin extends OsmandPlugin {
setText(null, null);
return true;
}
}
return false;
}
@ -528,7 +507,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
return R.drawable.ic_action_parking_dark;
}
String getFormattedTime(long timeInMillis, Activity ctx) {
String getFormattedTime(long timeInMillis) {
StringBuilder timeStringBuilder = new StringBuilder();
Time time = new Time();
time.set(timeInMillis);
@ -536,8 +515,8 @@ public class ParkingPositionPlugin extends OsmandPlugin {
timeStringBuilder.append(":");
int minute = time.minute;
timeStringBuilder.append(minute < 10 ? "0" + minute : minute);
if (!DateFormat.is24HourFormat(ctx)) {
timeStringBuilder.append(time.hour >= 12 ? ctx.getString(R.string.osmand_parking_pm) : ctx
if (!DateFormat.is24HourFormat(app)) {
timeStringBuilder.append(time.hour >= 12 ? app.getString(R.string.osmand_parking_pm) : app
.getString(R.string.osmand_parking_am));
}
return timeStringBuilder.toString();
@ -573,7 +552,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
if (getParkingType()) {
title.append(ctx.getString(R.string.pick_up_till)).append(" ");
long endTime = getParkingTime();
title.append(getFormattedTime(endTime, ctx));
title.append(getFormattedTime(endTime));
} else {
title.append(ctx.getString(R.string.osmand_parking_position_name));
}
@ -582,7 +561,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
public String getParkingStartDesc(Activity ctx) {
StringBuilder parkingStartDesc = new StringBuilder();
String startTime = getFormattedTime(getStartParkingTime(), ctx);
String startTime = getFormattedTime(getStartParkingTime());
if (getParkingType()) {
parkingStartDesc.append(ctx.getString(R.string.osmand_parking_position_name));
parkingStartDesc.append(", ");
@ -617,7 +596,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
public String getParkingDescription(Activity ctx) {
StringBuilder timeLimitDesc = new StringBuilder();
timeLimitDesc.append(ctx.getString(R.string.osmand_parking_position_description_add_time) + " ");
timeLimitDesc.append(getFormattedTime(getStartParkingTime(), ctx) + ".");
timeLimitDesc.append(getFormattedTime(getStartParkingTime()) + ".");
if (getParkingType()) {
// long parkingTime = settings.getParkingTime();
// long parkingStartTime = settings.getStartParkingTime();
@ -633,7 +612,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
// map.getString(R.string.osmand_parking_am));
// }
timeLimitDesc.append(ctx.getString(R.string.osmand_parking_position_description_add) + " ");
timeLimitDesc.append(getFormattedTime(getParkingTime(),ctx));
timeLimitDesc.append(getFormattedTime(getParkingTime()));
}
return ctx.getString(R.string.osmand_parking_position_description, timeLimitDesc.toString());
}

View file

@ -64,12 +64,12 @@ public class ParkingTypeBottomSheetDialogFragment extends MenuBottomSheetDialogF
plugin.showDeleteEventWarning(mapActivity);
}
if (limited) {
plugin.setParkingPosition(mapActivity, latitude, longitude, true);
plugin.setParkingPosition(latitude, longitude, true);
plugin.showSetTimeLimitDialog(mapActivity, new Dialog(getContext()));
mapActivity.refreshMap();
} else {
plugin.addOrRemoveParkingEvent(false);
plugin.setParkingPosition(mapActivity, latitude, longitude, false);
plugin.setParkingPosition(latitude, longitude, false);
plugin.showContextMenuIfNeeded(mapActivity, true);
mapActivity.refreshMap();
}