Refactored context menu nullables
This commit is contained in:
parent
f0ca7e3796
commit
acb9975535
15 changed files with 825 additions and 410 deletions
|
@ -64,17 +64,24 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
@Nullable
|
||||
private MapActivity mapActivity;
|
||||
|
||||
@Nullable
|
||||
private MapMultiSelectionMenu mapMultiSelectionMenu;
|
||||
|
||||
@Nullable
|
||||
private FavoritePointEditor favoritePointEditor;
|
||||
@Nullable
|
||||
private WptPtEditor wptPtEditor;
|
||||
@Nullable
|
||||
private RtePtEditor rtePtEditor;
|
||||
@Nullable
|
||||
private MapMarkerEditor mapMarkerEditor;
|
||||
|
||||
private boolean active;
|
||||
private LatLon latLon;
|
||||
private PointDescription pointDescription;
|
||||
@Nullable
|
||||
private Object object;
|
||||
@Nullable
|
||||
private MenuController menuController;
|
||||
|
||||
private LatLon mapCenter;
|
||||
|
@ -148,9 +155,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
this.mapActivity = mapActivity;
|
||||
|
||||
MapMultiSelectionMenu mapMultiSelectionMenu = getMultiSelectionMenu();
|
||||
if (mapMultiSelectionMenu == null) {
|
||||
if (mapActivity != null) {
|
||||
mapMultiSelectionMenu = new MapMultiSelectionMenu(mapActivity);
|
||||
this.mapMultiSelectionMenu = new MapMultiSelectionMenu(mapActivity);
|
||||
}
|
||||
} else {
|
||||
mapMultiSelectionMenu.setMapActivity(mapActivity);
|
||||
|
@ -171,12 +179,17 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
if (active && mapActivity != null) {
|
||||
acquireMenuController(false);
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon);
|
||||
menuController.addPlainMenuItems(typeStr, getPointDescription(), getLatLon());
|
||||
}
|
||||
MenuAction searchDoneAction = this.searchDoneAction;
|
||||
if (searchDoneAction != null && searchDoneAction.dlg != null && searchDoneAction.dlg.getOwnerActivity() != mapActivity) {
|
||||
searchDoneAction.dlg = buildSearchActionDialog();
|
||||
searchDoneAction.dlg.show();
|
||||
ProgressDialog dlg = buildSearchActionDialog();
|
||||
searchDoneAction.dlg = dlg;
|
||||
if (dlg != null) {
|
||||
dlg.show();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
menuController = null;
|
||||
|
@ -198,34 +211,45 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
public void hideMenues() {
|
||||
if (isVisible()) {
|
||||
hide();
|
||||
} else if (mapMultiSelectionMenu.isVisible()) {
|
||||
mapMultiSelectionMenu.hide();
|
||||
} else {
|
||||
MapMultiSelectionMenu mapMultiSelectionMenu = getMultiSelectionMenu();
|
||||
if (mapMultiSelectionMenu != null && mapMultiSelectionMenu.isVisible()) {
|
||||
mapMultiSelectionMenu.hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FavoritePointEditor getFavoritePointEditor() {
|
||||
if (favoritePointEditor == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (favoritePointEditor == null && mapActivity != null) {
|
||||
favoritePointEditor = new FavoritePointEditor(mapActivity);
|
||||
}
|
||||
return favoritePointEditor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WptPtEditor getWptPtPointEditor() {
|
||||
if (wptPtEditor == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (wptPtEditor == null && mapActivity != null) {
|
||||
wptPtEditor = new WptPtEditor(mapActivity);
|
||||
}
|
||||
return wptPtEditor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RtePtEditor getRtePtPointEditor() {
|
||||
if (rtePtEditor == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (rtePtEditor == null && mapActivity != null) {
|
||||
rtePtEditor = new RtePtEditor(mapActivity);
|
||||
}
|
||||
return rtePtEditor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapMarkerEditor getMapMarkerEditor() {
|
||||
if (mapMarkerEditor == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapMarkerEditor == null && mapActivity != null) {
|
||||
mapMarkerEditor = new MapMarkerEditor(mapActivity);
|
||||
}
|
||||
return mapMarkerEditor;
|
||||
|
@ -285,15 +309,17 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
return pointDescription;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public boolean isExtended() {
|
||||
return menuController != null;
|
||||
return getMenuController() != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public MenuController getMenuController() {
|
||||
return menuController;
|
||||
|
@ -310,14 +336,16 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
@Nullable Object object,
|
||||
boolean update, boolean restorePrevious) {
|
||||
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
|
||||
Object thisObject = getObject();
|
||||
if (!update && isVisible()) {
|
||||
if (this.object == null || !this.object.equals(object)) {
|
||||
if (thisObject == null || !thisObject.equals(object)) {
|
||||
hide();
|
||||
} else {
|
||||
return false;
|
||||
|
@ -332,12 +360,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
this.pointDescription = pointDescription;
|
||||
}
|
||||
|
||||
MenuController menuController = getMenuController();
|
||||
boolean needAcquireMenuController = menuController == null
|
||||
|| appModeChanged
|
||||
|| !update
|
||||
|| this.object == null && object != null
|
||||
|| this.object != null && object == null
|
||||
|| (this.object != null && object != null && !this.object.getClass().equals(object.getClass()));
|
||||
|| thisObject == null && object != null
|
||||
|| thisObject != null && object == null
|
||||
|| (thisObject != null && !thisObject.getClass().equals(object.getClass()));
|
||||
|
||||
this.latLon = latLon;
|
||||
this.object = object;
|
||||
|
@ -361,7 +390,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
if (menuController != null) {
|
||||
menuController.clearPlainMenuItems();
|
||||
menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon);
|
||||
menuController.addPlainMenuItems(typeStr, getPointDescription(), getLatLon());
|
||||
}
|
||||
|
||||
if (mapPosition != 0) {
|
||||
|
@ -383,9 +412,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if (!isVisible()) {
|
||||
boolean wasInit = true;
|
||||
if (appModeChanged) {
|
||||
wasInit = init(latLon, pointDescription, object);
|
||||
wasInit = init(getLatLon(), getPointDescription(), getObject());
|
||||
}
|
||||
if (wasInit && !MapContextMenuFragment.showInstance(this, mapActivity, true)) {
|
||||
if (wasInit && !MapContextMenuFragment.showInstance(this, getMapActivity(), true)) {
|
||||
active = false;
|
||||
}
|
||||
} else {
|
||||
|
@ -399,6 +428,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
public void show(@NonNull LatLon latLon,
|
||||
@Nullable PointDescription pointDescription,
|
||||
@Nullable Object object) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null && init(latLon, pointDescription, object)) {
|
||||
mapActivity.getMyApplication().logEvent(mapActivity, "open_context_menu");
|
||||
showInternal();
|
||||
|
@ -406,10 +436,12 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
private void showInternal() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
if (!MapContextMenuFragment.showInstance(this, mapActivity, centerMarker)) {
|
||||
active = false;
|
||||
} else {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
menuController.onShow();
|
||||
}
|
||||
|
@ -420,6 +452,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void update(LatLon latLon, PointDescription pointDescription, Object object) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
|
||||
init(latLon, pointDescription, object, true, false);
|
||||
|
@ -433,7 +466,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void showOrUpdate(LatLon latLon, PointDescription pointDescription, Object object) {
|
||||
if (isVisible() && this.object != null && this.object.equals(object)) {
|
||||
Object thisObject = getObject();
|
||||
if (isVisible() && thisObject != null && thisObject.equals(object)) {
|
||||
update(latLon, pointDescription, object);
|
||||
} else {
|
||||
show(latLon, pointDescription, object);
|
||||
|
@ -451,6 +485,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public boolean navigateInPedestrianMode() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.navigateInPedestrianMode();
|
||||
}
|
||||
|
@ -461,18 +496,21 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
boolean result = false;
|
||||
if (active) {
|
||||
active = false;
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
Object object = getObject();
|
||||
if (object instanceof MapMarker) {
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().removeListener(this);
|
||||
}
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
if (menuController.hasBackAction()) {
|
||||
clearHistoryStack();
|
||||
}
|
||||
menuController.onClose();
|
||||
}
|
||||
if (this.object != null) {
|
||||
clearSelectedObject(this.object);
|
||||
if (object != null) {
|
||||
clearSelectedObject(object);
|
||||
}
|
||||
result = hide();
|
||||
if (menuController != null) {
|
||||
|
@ -486,11 +524,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
public boolean hide(boolean animated) {
|
||||
boolean result = false;
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
if (mapPosition != 0) {
|
||||
mapActivity.getMapView().setMapPosition(mapPosition);
|
||||
mapPosition = 0;
|
||||
}
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
menuController.onHide();
|
||||
}
|
||||
|
@ -511,6 +551,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void updateControlsVisibility(boolean menuVisible) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
int topControlsVisibility = shouldShowTopControls(menuVisible) ? View.VISIBLE : View.GONE;
|
||||
mapActivity.findViewById(R.id.map_center_info).setVisibility(topControlsVisibility);
|
||||
|
@ -539,6 +580,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
// timeout in msec
|
||||
public void hideWithTimeout(long timeout) {
|
||||
autoHide = true;
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMyApplication().runInUIThread(new Runnable() {
|
||||
@Override
|
||||
|
@ -567,6 +609,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
@Override
|
||||
public void onMapMarkerChanged(MapMarker mapMarker) {
|
||||
Object object = getObject();
|
||||
if (object != null && object.equals(mapMarker)) {
|
||||
String address = mapMarker.getOnlyName();
|
||||
updateTitle(address);
|
||||
|
@ -579,6 +622,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
@Override
|
||||
public void onTargetPointChanged(TargetPoint targetPoint) {
|
||||
Object object = getObject();
|
||||
if (object != null && object.equals(targetPoint)) {
|
||||
String address = targetPoint.getOnlyName();
|
||||
updateTitle(address);
|
||||
|
@ -587,7 +631,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
private void updateTitle(String address) {
|
||||
nameStr = address;
|
||||
pointDescription.setName(address);
|
||||
getPointDescription().setName(address);
|
||||
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
|
||||
if (fragmentRef != null)
|
||||
fragmentRef.get().refreshTitle();
|
||||
|
@ -599,6 +643,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
private void clearSelectedObject(Object object) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapLayers().getContextMenuLayer().setSelectedObject(null);
|
||||
if (object != null) {
|
||||
|
@ -617,6 +662,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
private void setSelectedObject(@Nullable Object object) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapLayers().getContextMenuLayer().setSelectedObject(object);
|
||||
if (object != null) {
|
||||
|
@ -636,6 +682,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
private boolean acquireMenuController(boolean restorePrevious) {
|
||||
MapContextMenuData menuData = null;
|
||||
MenuController menuController = getMenuController();
|
||||
LatLon latLon = getLatLon();
|
||||
Object object = getObject();
|
||||
PointDescription pointDescription = getPointDescription();
|
||||
if (menuController != null) {
|
||||
if (menuController.isActive() && !restorePrevious) {
|
||||
menuData = new MapContextMenuData(
|
||||
|
@ -644,8 +694,14 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
menuController.onAcquireNewController(pointDescription, object);
|
||||
}
|
||||
menuController = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.STANDARD);
|
||||
if (menuController.setActive(true)) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
menuController = MenuController.getMenuController(mapActivity, latLon, pointDescription, object, MenuType.STANDARD);
|
||||
} else {
|
||||
menuController = null;
|
||||
}
|
||||
this.menuController = menuController;
|
||||
if (menuController != null && menuController.setActive(true)) {
|
||||
menuController.setMapContextMenu(this);
|
||||
if (menuData != null && (object != menuData.getObject())
|
||||
&& (menuController.hasBackAction() || menuData.hasBackAction())) {
|
||||
|
@ -694,24 +750,28 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
public void backToolbarAction(MenuController menuController) {
|
||||
menuController.onClose();
|
||||
if (!showPreviousMenu() && this.menuController.getClass() == menuController.getClass()) {
|
||||
MenuController thisMenuController = getMenuController();
|
||||
if (!showPreviousMenu() && thisMenuController != null &&
|
||||
thisMenuController.getClass() == menuController.getClass()) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasActiveToolbar() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
TopToolbarController toolbarController = mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU);
|
||||
return toolbarController != null && toolbarController instanceof ContextMenuToolbarController;
|
||||
return toolbarController instanceof ContextMenuToolbarController;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void closeActiveToolbar() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
TopToolbarController toolbarController = mapActivity.getTopToolbarController(TopToolbarControllerType.CONTEXT_MENU);
|
||||
if (toolbarController != null && toolbarController instanceof ContextMenuToolbarController) {
|
||||
if (toolbarController instanceof ContextMenuToolbarController) {
|
||||
MenuController menuController = ((ContextMenuToolbarController) toolbarController).getMenuController();
|
||||
closeToolbar(menuController);
|
||||
}
|
||||
|
@ -719,11 +779,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void closeToolbar(MenuController menuController) {
|
||||
if (this.menuController.getClass() == menuController.getClass()) {
|
||||
MenuController thisMenuController = getMenuController();
|
||||
if (thisMenuController != null && thisMenuController.getClass() == menuController.getClass()) {
|
||||
close();
|
||||
} else {
|
||||
clearHistoryStack();
|
||||
menuController.onClose();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
|
@ -732,6 +794,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
public boolean onSingleTapOnMap() {
|
||||
boolean result = false;
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController == null || !menuController.handleSingleTapOnMap()) {
|
||||
if (menuController != null && !menuController.isClosable()) {
|
||||
result = hide();
|
||||
|
@ -739,6 +802,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
updateMapCenter(null);
|
||||
result = close();
|
||||
}
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null && mapActivity.getMapLayers().getMapQuickActionLayer().isLayerOn()) {
|
||||
mapActivity.getMapLayers().getMapQuickActionLayer().refreshLayer();
|
||||
}
|
||||
|
@ -752,7 +816,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if (fragmentRef != null) {
|
||||
fragmentRef.get().refreshTitle();
|
||||
}
|
||||
|
||||
MenuAction searchDoneAction = this.searchDoneAction;
|
||||
if (searchDoneAction != null) {
|
||||
if (searchDoneAction.dlg != null) {
|
||||
try {
|
||||
|
@ -764,12 +828,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
}
|
||||
searchDoneAction.run();
|
||||
searchDoneAction = null;
|
||||
this.searchDoneAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WeakReference<MapContextMenuFragment> findMenuFragment() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
Fragment fragment = mapActivity != null
|
||||
? mapActivity.getSupportFragmentManager().findFragmentByTag(MapContextMenuFragment.TAG) : null;
|
||||
if (fragment != null && !fragment.isDetached()) {
|
||||
|
@ -784,8 +849,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public int getFavActionStringId() {
|
||||
if (menuController != null)
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getFavActionStringId();
|
||||
}
|
||||
return R.string.shared_string_add;
|
||||
}
|
||||
|
||||
|
@ -794,6 +861,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public int getWaypointActionStringId() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getWaypointActionStringId();
|
||||
}
|
||||
|
@ -801,6 +869,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public boolean isButtonWaypointEnabled() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.isWaypointButtonEnabled();
|
||||
}
|
||||
|
@ -809,6 +878,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
protected void acquireIcons() {
|
||||
super.acquireIcons();
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
favActionIconId = menuController.getFavActionIconId();
|
||||
waypointActionIconId = menuController.getWaypointActionIconId();
|
||||
|
@ -820,6 +890,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
public int getFabIconId() {
|
||||
int res = R.drawable.map_directions;
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
|
||||
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
|
||||
|
@ -830,6 +901,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public List<TransportStopRoute> getTransportStopRoutes() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getTransportStopRoutes();
|
||||
}
|
||||
|
@ -837,6 +909,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public List<TransportStopRoute> getLocalTransportStopRoutes() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getLocalTransportStopRoutes();
|
||||
}
|
||||
|
@ -844,6 +917,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public List<TransportStopRoute> getNearbyTransportStopRoutes() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getNearbyTransportStopRoutes();
|
||||
}
|
||||
|
@ -851,6 +925,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void navigateButtonPressed() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
if (navigateInPedestrianMode()) {
|
||||
mapActivity.getMyApplication().getSettings().APPLICATION_MODE.set(ApplicationMode.PEDESTRIAN);
|
||||
|
@ -878,16 +953,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void buttonWaypointPressed() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
MapMarker marker = getMapMarker();
|
||||
if (marker != null) {
|
||||
getMapMarkerEditor().edit(marker);
|
||||
MapMarkerEditor mapMarkerEditor = getMapMarkerEditor();
|
||||
if (mapMarkerEditor != null) {
|
||||
mapMarkerEditor.edit(marker);
|
||||
}
|
||||
} else {
|
||||
String mapObjectName = null;
|
||||
Object object = getObject();
|
||||
if (object instanceof Amenity) {
|
||||
Amenity amenity = (Amenity) object;
|
||||
mapObjectName = amenity.getName() + "_" + amenity.getType().getKeyName();
|
||||
}
|
||||
LatLon latLon = getLatLon();
|
||||
mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(),
|
||||
getPointDescriptionForMarker(), mapObjectName);
|
||||
close();
|
||||
|
@ -897,11 +978,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
@Nullable
|
||||
private MapMarker getMapMarker() {
|
||||
Object correspondingObj = menuController.getCorrespondingMapObject();
|
||||
if (correspondingObj != null && correspondingObj instanceof MapMarker) {
|
||||
MenuController menuController = getMenuController();
|
||||
Object correspondingObj = menuController != null ? menuController.getCorrespondingMapObject() : null;
|
||||
if (correspondingObj instanceof MapMarker) {
|
||||
return (MapMarker) correspondingObj;
|
||||
}
|
||||
if (object != null && object instanceof MapMarker) {
|
||||
Object object = getObject();
|
||||
if (object instanceof MapMarker) {
|
||||
return (MapMarker) object;
|
||||
}
|
||||
return null;
|
||||
|
@ -909,17 +992,22 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
|
||||
public void buttonFavoritePressed() {
|
||||
if (object != null && object instanceof FavouritePoint) {
|
||||
getFavoritePointEditor().edit((FavouritePoint) object);
|
||||
Object object = getObject();
|
||||
if (object instanceof FavouritePoint) {
|
||||
FavoritePointEditor favoritePointEditor = getFavoritePointEditor();
|
||||
if (favoritePointEditor != null) {
|
||||
favoritePointEditor.edit((FavouritePoint) object);
|
||||
}
|
||||
} else {
|
||||
callMenuAction(true, new MenuAction() {
|
||||
@Override
|
||||
public void run() {
|
||||
String title = getTitleStr();
|
||||
if (pointDescription.isFavorite() || !hasValidTitle()) {
|
||||
if (getPointDescription().isFavorite() || !hasValidTitle()) {
|
||||
title = "";
|
||||
}
|
||||
String originObjectName = "";
|
||||
Object object = getObject();
|
||||
if (object != null) {
|
||||
if (object instanceof Amenity) {
|
||||
originObjectName = ((Amenity) object).toStringEn();
|
||||
|
@ -927,69 +1015,96 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
originObjectName = ((TransportStop) object).toStringEn();
|
||||
}
|
||||
}
|
||||
getFavoritePointEditor().add(latLon, title, originObjectName);
|
||||
FavoritePointEditor favoritePointEditor = getFavoritePointEditor();
|
||||
if (favoritePointEditor != null) {
|
||||
favoritePointEditor.add(getLatLon(), title, originObjectName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonSharePressed() {
|
||||
MenuController menuController = getMenuController();
|
||||
LatLon latLon = getLatLon();
|
||||
if (menuController != null) {
|
||||
menuController.share(latLon, nameStr, streetStr);
|
||||
} else {
|
||||
ShareMenu.show(latLon, nameStr, streetStr, mapActivity);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
ShareMenu.show(latLon, nameStr, streetStr, mapActivity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void buttonMorePressed() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter();
|
||||
LatLon latLon = getLatLon();
|
||||
for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) {
|
||||
layer.populateObjectContextMenu(latLon, object, menuAdapter, mapActivity);
|
||||
layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity);
|
||||
}
|
||||
|
||||
mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, object);
|
||||
mapActivity.getMapActions().contextMenuPoint(latLon.getLatitude(), latLon.getLongitude(), menuAdapter, getObject());
|
||||
}
|
||||
}
|
||||
|
||||
private void callMenuAction(boolean waitForAddressLookup, MenuAction menuAction) {
|
||||
if (searchingAddress() && waitForAddressLookup) {
|
||||
menuAction.dlg = buildSearchActionDialog();
|
||||
menuAction.dlg.show();
|
||||
ProgressDialog dlg = buildSearchActionDialog();
|
||||
menuAction.dlg = dlg;
|
||||
if (dlg != null) {
|
||||
dlg.show();
|
||||
}
|
||||
searchDoneAction = menuAction;
|
||||
} else {
|
||||
menuAction.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ProgressDialog buildSearchActionDialog() {
|
||||
ProgressDialog dlg = new ProgressDialog(mapActivity);
|
||||
dlg.setTitle("");
|
||||
dlg.setMessage(searchAddressStr);
|
||||
dlg.setButton(Dialog.BUTTON_NEGATIVE, mapActivity.getResources().getString(R.string.shared_string_skip), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
cancelSearchAddress();
|
||||
}
|
||||
});
|
||||
return dlg;
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
ProgressDialog dlg = new ProgressDialog(mapActivity);
|
||||
dlg.setTitle("");
|
||||
dlg.setMessage(searchAddressStr);
|
||||
dlg.setButton(Dialog.BUTTON_NEGATIVE, mapActivity.getResources().getString(R.string.shared_string_skip), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
cancelSearchAddress();
|
||||
}
|
||||
});
|
||||
return dlg;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean openEditor() {
|
||||
Object object = getObject();
|
||||
if (object != null) {
|
||||
if (object instanceof FavouritePoint) {
|
||||
getFavoritePointEditor().edit((FavouritePoint) object);
|
||||
return true;
|
||||
FavoritePointEditor favoritePointEditor = getFavoritePointEditor();
|
||||
if (favoritePointEditor != null) {
|
||||
favoritePointEditor.edit((FavouritePoint) object);
|
||||
return true;
|
||||
}
|
||||
} else if (object instanceof WptPt) {
|
||||
getWptPtPointEditor().edit((WptPt) object);
|
||||
return true;
|
||||
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
|
||||
if (wptPtPointEditor != null) {
|
||||
wptPtPointEditor.edit((WptPt) object);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addAsLastIntermediate() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMyApplication().getTargetPointsHelper().navigateToPoint(latLon,
|
||||
mapActivity.getMyApplication().getTargetPointsHelper().navigateToPoint(getLatLon(),
|
||||
true, mapActivity.getMyApplication().getTargetPointsHelper().getIntermediatePoints().size(),
|
||||
getPointDescriptionForTarget());
|
||||
close();
|
||||
|
@ -997,9 +1112,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void addWptPt() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
String title = getTitleStr();
|
||||
if (pointDescription.isWpt() || !hasValidTitle()) {
|
||||
if (getPointDescription().isWpt() || !hasValidTitle()) {
|
||||
title = "";
|
||||
}
|
||||
|
||||
|
@ -1008,7 +1124,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
if ((list.isEmpty() || (list.size() == 1 && list.get(0).getGpxFile().showCurrentTrack))
|
||||
&& OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) {
|
||||
GPXFile gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
|
||||
getWptPtPointEditor().add(gpxFile, latLon, title);
|
||||
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
|
||||
if (wptPtPointEditor != null) {
|
||||
wptPtPointEditor.add(gpxFile, getLatLon(), title);
|
||||
}
|
||||
} else {
|
||||
addNewWptToGPXFile(title);
|
||||
}
|
||||
|
@ -1016,12 +1135,16 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void addWptPt(LatLon latLon, String title, String categoryName, int categoryColor, boolean skipDialog) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
final List<SelectedGpxFile> list
|
||||
= mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
if (list.isEmpty() || (list.size() == 1 && list.get(0).getGpxFile().showCurrentTrack)) {
|
||||
GPXFile gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
|
||||
getWptPtPointEditor().add(gpxFile, latLon, title, categoryName, categoryColor, skipDialog);
|
||||
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
|
||||
if (wptPtPointEditor != null) {
|
||||
wptPtPointEditor.add(gpxFile, latLon, title, categoryName, categoryColor, skipDialog);
|
||||
}
|
||||
} else {
|
||||
addNewWptToGPXFile(latLon, title, categoryName, categoryColor, skipDialog);
|
||||
}
|
||||
|
@ -1029,18 +1152,24 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public void editWptPt() {
|
||||
if (object != null && object instanceof WptPt) {
|
||||
getWptPtPointEditor().edit((WptPt) object);
|
||||
Object object = getObject();
|
||||
if (object instanceof WptPt) {
|
||||
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
|
||||
if (wptPtPointEditor != null) {
|
||||
wptPtPointEditor.edit((WptPt) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewWptToGPXFile(final LatLon latLon, final String title,
|
||||
final String categoryName,
|
||||
final int categoryColor, final boolean skipDialog) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
|
||||
@Override
|
||||
public boolean processResult(GPXFile[] result) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
GPXFile gpxFile;
|
||||
if (result != null && result.length > 0) {
|
||||
|
@ -1048,21 +1177,25 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
} else {
|
||||
gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
|
||||
}
|
||||
getWptPtPointEditor().add(gpxFile, latLon, title, categoryName, categoryColor, skipDialog);
|
||||
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
|
||||
if (wptPtPointEditor != null) {
|
||||
wptPtPointEditor.add(gpxFile, latLon, title, categoryName, categoryColor, skipDialog);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
GpxUiHelper.selectSingleGPXFile(mapActivity, true, callbackWithObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewWptToGPXFile(final String title) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
|
||||
@Override
|
||||
public boolean processResult(GPXFile[] result) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
GPXFile gpxFile;
|
||||
if (result != null && result.length > 0) {
|
||||
|
@ -1070,7 +1203,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
} else {
|
||||
gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
|
||||
}
|
||||
getWptPtPointEditor().add(gpxFile, latLon, title);
|
||||
WptPtEditor wptPtPointEditor = getWptPtPointEditor();
|
||||
if (wptPtPointEditor != null) {
|
||||
wptPtPointEditor.add(gpxFile, getLatLon(), title);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1082,7 +1218,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
@Nullable
|
||||
public PointDescription getPointDescriptionForTarget() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
PointDescription pointDescription = getPointDescription();
|
||||
if (pointDescription.isLocation()
|
||||
&& pointDescription.getName().equals(PointDescription.getAddressNotFoundStr(mapActivity))) {
|
||||
return new PointDescription(PointDescription.POINT_TYPE_LOCATION, "");
|
||||
|
@ -1097,6 +1235,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
@Nullable
|
||||
public PointDescription getPointDescriptionForMarker() {
|
||||
PointDescription pd = getPointDescriptionForTarget();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (pd != null && mapActivity != null) {
|
||||
if (Algorithms.isEmpty(pd.getName()) && !Algorithms.isEmpty(nameStr)
|
||||
&& !nameStr.equals(PointDescription.getAddressNotFoundStr(mapActivity))) {
|
||||
|
@ -1117,10 +1256,12 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public boolean isLandscapeLayout() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController != null && menuController.isLandscapeLayout();
|
||||
}
|
||||
|
||||
public int getLandscapeWidthPx() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getLandscapeWidthPx();
|
||||
} else {
|
||||
|
@ -1147,20 +1288,24 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public boolean slideUp() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController != null && menuController.slideUp();
|
||||
}
|
||||
|
||||
public boolean slideDown() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController != null && menuController.slideDown();
|
||||
}
|
||||
|
||||
public void build(View rootView) {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
menuController.build(rootView);
|
||||
}
|
||||
}
|
||||
|
||||
public int getCurrentMenuState() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getCurrentMenuState();
|
||||
} else {
|
||||
|
@ -1169,6 +1314,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public float getHalfScreenMaxHeightKoef() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getHalfScreenMaxHeightKoef();
|
||||
} else {
|
||||
|
@ -1177,6 +1323,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public int getSlideInAnimation() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getSlideInAnimation();
|
||||
} else {
|
||||
|
@ -1185,6 +1332,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public int getSlideOutAnimation() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getSlideOutAnimation();
|
||||
} else {
|
||||
|
@ -1193,6 +1341,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public TitleButtonController getLeftTitleButtonController() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getLeftTitleButtonController();
|
||||
} else {
|
||||
|
@ -1201,6 +1350,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public TitleButtonController getRightTitleButtonController() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getRightTitleButtonController();
|
||||
} else {
|
||||
|
@ -1209,6 +1359,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public TitleButtonController getBottomTitleButtonController() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getBottomTitleButtonController();
|
||||
} else {
|
||||
|
@ -1217,6 +1368,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public TitleButtonController getLeftDownloadButtonController() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getLeftDownloadButtonController();
|
||||
} else {
|
||||
|
@ -1225,6 +1377,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public TitleButtonController getRightDownloadButtonController() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getRightDownloadButtonController();
|
||||
} else {
|
||||
|
@ -1233,6 +1386,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public TitleProgressController getTitleProgressController() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getTitleProgressController();
|
||||
} else {
|
||||
|
@ -1241,30 +1395,37 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public boolean supportZoomIn() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController == null || menuController.supportZoomIn();
|
||||
}
|
||||
|
||||
public boolean navigateButtonVisible() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController == null || menuController.navigateButtonVisible();
|
||||
}
|
||||
|
||||
public boolean zoomButtonsVisible() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController == null || menuController.zoomButtonsVisible();
|
||||
}
|
||||
|
||||
public boolean isClosable() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController == null || menuController.isClosable();
|
||||
}
|
||||
|
||||
public boolean buttonsVisible() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController == null || menuController.buttonsVisible();
|
||||
}
|
||||
|
||||
public boolean displayDistanceDirection() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController != null && menuController.displayDistanceDirection();
|
||||
}
|
||||
|
||||
public String getSubtypeStr() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getSubtypeStr();
|
||||
}
|
||||
|
@ -1272,6 +1433,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public Drawable getSubtypeIcon() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getSubtypeIcon();
|
||||
}
|
||||
|
@ -1279,6 +1441,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public int getAdditionalInfoColor() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getAdditionalInfoColorId();
|
||||
}
|
||||
|
@ -1286,6 +1449,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public CharSequence getAdditionalInfo() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getAdditionalInfoStr();
|
||||
}
|
||||
|
@ -1293,6 +1457,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public int getAdditionalInfoIconRes() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return menuController.getAdditionalInfoIconRes();
|
||||
}
|
||||
|
@ -1300,26 +1465,32 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
}
|
||||
|
||||
public boolean isMapDownloaded() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController != null && menuController.isMapDownloaded();
|
||||
}
|
||||
|
||||
public void updateData() {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
menuController.updateData();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCustomAddressLine() {
|
||||
MenuController menuController = getMenuController();
|
||||
return menuController != null && menuController.hasCustomAddressLine();
|
||||
}
|
||||
|
||||
public void buildCustomAddressLine(LinearLayout ll) {
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
menuController.buildCustomAddressLine(ll);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNightMode() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
MenuController menuController = getMenuController();
|
||||
if (menuController != null) {
|
||||
return !menuController.isLight();
|
||||
} else if (mapActivity != null) {
|
||||
|
@ -1360,6 +1531,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
|
|||
|
||||
public void updateLocation(final boolean centerChanged, final boolean locationChanged,
|
||||
final boolean compassChanged) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (inLocationUpdate || mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ import net.osmand.util.Algorithms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
|
||||
|
||||
|
||||
|
@ -154,10 +153,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
processScreenHeight(container);
|
||||
|
||||
menu = getMapActivity().getContextMenu();
|
||||
updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache();
|
||||
menu = mapActivity.getContextMenu();
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
|
||||
|
||||
markerPaddingPx = dpToPx(MARKER_PADDING_DP);
|
||||
markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP);
|
||||
|
@ -171,7 +176,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
if (!menu.isActive()) {
|
||||
return view;
|
||||
}
|
||||
AndroidUtils.addStatusBarPadding21v(getMapActivity(), view);
|
||||
AndroidUtils.addStatusBarPadding21v(mapActivity, view);
|
||||
|
||||
nightMode = menu.isNightMode();
|
||||
mainView = view.findViewById(R.id.context_menu_main);
|
||||
|
@ -197,7 +202,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
});
|
||||
updateVisibility(topButtonContainer, 0);
|
||||
|
||||
map = getMapActivity().getMapView();
|
||||
map = mapActivity.getMapView();
|
||||
RotatedTileBox box = map.getCurrentRotatedTileBox().copy();
|
||||
customMapCenter = menu.getMapCenter() != null;
|
||||
if (!customMapCenter) {
|
||||
|
@ -291,7 +296,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
if (menu.isLandscapeLayout()) {
|
||||
final TypedValue typedValueAttr = new TypedValue();
|
||||
getMapActivity().getTheme().resolveAttribute(R.attr.left_menu_view_bg, typedValueAttr, true);
|
||||
mapActivity.getTheme().resolveAttribute(R.attr.left_menu_view_bg, typedValueAttr, true);
|
||||
mainView.setBackgroundResource(typedValueAttr.resourceId);
|
||||
mainView.setLayoutParams(new FrameLayout.LayoutParams(menu.getLandscapeWidthPx(),
|
||||
ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
|
@ -457,7 +462,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
};
|
||||
|
||||
View topShadowAllView = view.findViewById(R.id.context_menu_top_shadow_all);
|
||||
AndroidUtils.setBackground(getMapActivity(), topShadowAllView, nightMode, R.drawable.bg_map_context_menu_light,
|
||||
AndroidUtils.setBackground(mapActivity, topShadowAllView, nightMode, R.drawable.bg_map_context_menu_light,
|
||||
R.drawable.bg_map_context_menu_dark);
|
||||
|
||||
((InterceptorLinearLayout) mainView).setListener(slideTouchListener);
|
||||
|
@ -465,19 +470,19 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
buildHeader();
|
||||
|
||||
((TextView) view.findViewById(R.id.context_menu_line1)).setTextColor(ContextCompat.getColor(getContext(),
|
||||
((TextView) view.findViewById(R.id.context_menu_line1)).setTextColor(ContextCompat.getColor(mapActivity,
|
||||
nightMode ? R.color.ctx_menu_title_color_dark : R.color.ctx_menu_title_color_light));
|
||||
View menuLine2 = view.findViewById(R.id.context_menu_line2);
|
||||
if (menuLine2 != null) {
|
||||
((TextView) menuLine2).setTextColor(ContextCompat.getColor(getContext(), R.color.ctx_menu_subtitle_color));
|
||||
((TextView) menuLine2).setTextColor(ContextCompat.getColor(mapActivity, R.color.ctx_menu_subtitle_color));
|
||||
}
|
||||
((TextView) view.findViewById(R.id.distance)).setTextColor(ContextCompat.getColor(getContext(),
|
||||
((TextView) view.findViewById(R.id.distance)).setTextColor(ContextCompat.getColor(mapActivity,
|
||||
nightMode ? R.color.ctx_menu_direction_color_dark : R.color.ctx_menu_direction_color_light));
|
||||
|
||||
AndroidUtils.setTextSecondaryColor(getMapActivity(),
|
||||
AndroidUtils.setTextSecondaryColor(mapActivity,
|
||||
(TextView) view.findViewById(R.id.title_button_right_text), nightMode);
|
||||
|
||||
AndroidUtils.setTextSecondaryColor(getMapActivity(),
|
||||
AndroidUtils.setTextSecondaryColor(mapActivity,
|
||||
(TextView) view.findViewById(R.id.progressTitle), nightMode);
|
||||
|
||||
// Zoom buttons
|
||||
|
@ -647,26 +652,33 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
return view;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private TransportStopRouteAdapter createTransportStopRouteAdapter(List<TransportStopRoute> routes, boolean needMoreItem) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app == null) {
|
||||
return null;
|
||||
}
|
||||
List<Object> items = new ArrayList<Object>(routes);
|
||||
if (needMoreItem) {
|
||||
items.add(TRANSPORT_BADGE_MORE_ITEM);
|
||||
}
|
||||
final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getMyApplication(), items, nightMode);
|
||||
final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(app, items, nightMode);
|
||||
adapter.setListener(new TransportStopRouteAdapter.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(int position) {
|
||||
Object object = adapter.getItem(position);
|
||||
if (object != null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (object != null && mapActivity != null) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
if (object instanceof TransportStopRoute) {
|
||||
TransportStopRoute route = (TransportStopRoute) object;
|
||||
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE,
|
||||
route.getDescription(getMapActivity().getMyApplication(), false));
|
||||
route.getDescription(app, false));
|
||||
menu.show(menu.getLatLon(), pd, route);
|
||||
TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer();
|
||||
TransportStopsLayer stopsLayer = mapActivity.getMapLayers().getTransportStopsLayer();
|
||||
stopsLayer.setRoute(route);
|
||||
int cz = route.calculateZoom(0, getMapActivity().getMapView().getCurrentRotatedTileBox());
|
||||
getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom());
|
||||
int cz = route.calculateZoom(0, mapActivity.getMapView().getCurrentRotatedTileBox());
|
||||
mapActivity.changeZoom(cz - mapActivity.getMapView().getZoom());
|
||||
} else if (object instanceof String) {
|
||||
if (object.equals(TRANSPORT_BADGE_MORE_ITEM)) {
|
||||
if (menu.isLandscapeLayout()) {
|
||||
|
@ -804,19 +816,22 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
private void updateImageButton(ImageButton button, int iconLightId, int iconDarkId, int bgLightId, int bgDarkId, boolean night) {
|
||||
button.setImageDrawable(getMapActivity().getMyApplication().getUIUtilities().getIcon(night ? iconDarkId : iconLightId));
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
button.setBackground(getMapActivity().getResources().getDrawable(night ? bgDarkId : bgLightId,
|
||||
getMapActivity().getTheme()));
|
||||
} else {
|
||||
button.setBackgroundDrawable(getMapActivity().getResources().getDrawable(night ? bgDarkId : bgLightId));
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
button.setImageDrawable(mapActivity.getMyApplication().getUIUtilities().getIcon(night ? iconDarkId : iconLightId));
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
|
||||
button.setBackground(mapActivity.getResources().getDrawable(night ? bgDarkId : bgLightId,
|
||||
mapActivity.getTheme()));
|
||||
} else {
|
||||
button.setBackgroundDrawable(mapActivity.getResources().getDrawable(night ? bgDarkId : bgLightId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void processScreenHeight(ViewParent parent) {
|
||||
View container = (View) parent;
|
||||
screenHeight = container.getHeight() + AndroidUtils.getStatusBarHeight(getActivity());
|
||||
viewHeight = screenHeight - AndroidUtils.getStatusBarHeight(getMapActivity());
|
||||
screenHeight = container.getHeight() + AndroidUtils.getStatusBarHeight(container.getContext());
|
||||
viewHeight = screenHeight - AndroidUtils.getStatusBarHeight(container.getContext());
|
||||
}
|
||||
|
||||
public void openMenuFullScreen() {
|
||||
|
@ -919,17 +934,23 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
|
||||
public void doZoomIn() {
|
||||
if (map.isZooming() && map.hasCustomMapRatio()) {
|
||||
getMapActivity().changeZoom(2, System.currentTimeMillis());
|
||||
} else {
|
||||
setCustomMapRatio();
|
||||
getMapActivity().changeZoom(1, System.currentTimeMillis());
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
if (map.isZooming() && map.hasCustomMapRatio()) {
|
||||
mapActivity.changeZoom(2, System.currentTimeMillis());
|
||||
} else {
|
||||
setCustomMapRatio();
|
||||
mapActivity.changeZoom(1, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doZoomOut() {
|
||||
setCustomMapRatio();
|
||||
getMapActivity().changeZoom(-1, System.currentTimeMillis());
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
setCustomMapRatio();
|
||||
mapActivity.changeZoom(-1, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust,
|
||||
|
@ -1028,7 +1049,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
|
||||
private void enableDisableButtons(View buttonView, TextView button, boolean enabled) {
|
||||
if (enabled) {
|
||||
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(getContext(), nightMode,
|
||||
ColorStateList buttonColorStateList = AndroidUtils.createPressedColorStateList(buttonView.getContext(), nightMode,
|
||||
R.color.ctx_menu_controller_button_text_color_light_n, R.color.ctx_menu_controller_button_text_color_light_p,
|
||||
R.color.ctx_menu_controller_button_text_color_dark_n, R.color.ctx_menu_controller_button_text_color_dark_p);
|
||||
|
||||
|
@ -1036,7 +1057,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
button.setTextColor(buttonColorStateList);
|
||||
} else {
|
||||
buttonView.setBackgroundResource(nightMode ? R.drawable.context_menu_controller_disabled_bg_dark : R.drawable.context_menu_controller_disabled_bg_light);
|
||||
button.setTextColor(ContextCompat.getColor(getContext(), nightMode ? R.color.ctx_menu_controller_disabled_text_color_dark : R.color.ctx_menu_controller_disabled_text_color_light));
|
||||
button.setTextColor(ContextCompat.getColor(buttonView.getContext(), nightMode ? R.color.ctx_menu_controller_disabled_text_color_dark : R.color.ctx_menu_controller_disabled_text_color_light));
|
||||
}
|
||||
button.setEnabled(enabled);
|
||||
}
|
||||
|
@ -1230,37 +1251,42 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
dismissMenu();
|
||||
return;
|
||||
}
|
||||
updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache();
|
||||
getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu);
|
||||
getMapActivity().getMapViewTrackingUtilities().setMapLinkedToLocation(false);
|
||||
wasDrawerDisabled = getMapActivity().isDrawerDisabled();
|
||||
if (!wasDrawerDisabled) {
|
||||
getMapActivity().disableDrawer();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
updateLocationViewCache = mapActivity.getMyApplication().getUIUtilities().getUpdateLocationViewCache();
|
||||
mapActivity.getMapViewTrackingUtilities().setContextMenu(menu);
|
||||
mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
|
||||
wasDrawerDisabled = mapActivity.isDrawerDisabled();
|
||||
if (!wasDrawerDisabled) {
|
||||
mapActivity.disableDrawer();
|
||||
}
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent != null && containerLayoutListener != null) {
|
||||
((View) parent).addOnLayoutChangeListener(containerLayoutListener);
|
||||
}
|
||||
menu.updateControlsVisibility(true);
|
||||
menu.onFragmentResume();
|
||||
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
|
||||
}
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent != null && containerLayoutListener != null) {
|
||||
((View) parent).addOnLayoutChangeListener(containerLayoutListener);
|
||||
}
|
||||
menu.updateControlsVisibility(true);
|
||||
menu.onFragmentResume();
|
||||
getMapActivity().getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
|
||||
if (view != null) {
|
||||
restoreCustomMapRatio();
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent != null && containerLayoutListener != null) {
|
||||
((View) parent).removeOnLayoutChangeListener(containerLayoutListener);
|
||||
}
|
||||
getMapActivity().getMapViewTrackingUtilities().setContextMenu(null);
|
||||
getMapActivity().getMapViewTrackingUtilities().setMapLinkedToLocation(false);
|
||||
if (!wasDrawerDisabled) {
|
||||
getMapActivity().enableDrawer();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapViewTrackingUtilities().setContextMenu(null);
|
||||
mapActivity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
|
||||
if (!wasDrawerDisabled) {
|
||||
mapActivity.enableDrawer();
|
||||
}
|
||||
menu.updateControlsVisibility(false);
|
||||
}
|
||||
menu.updateControlsVisibility(false);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
@ -1603,7 +1629,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
int colorId = menu.getAdditionalInfoColor();
|
||||
int additionalInfoIconRes = menu.getAdditionalInfoIconRes();
|
||||
if (colorId != 0) {
|
||||
additionalInfoTextView.setTextColor(ContextCompat.getColor(getContext(), colorId));
|
||||
additionalInfoTextView.setTextColor(ContextCompat.getColor(additionalInfoTextView.getContext(), colorId));
|
||||
if (additionalInfoIconRes != 0) {
|
||||
Drawable additionalIcon = getIcon(additionalInfoIconRes, colorId);
|
||||
additionalInfoImageView.setImageDrawable(additionalIcon);
|
||||
|
@ -1671,7 +1697,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
if (app != null && activity != null && view != null) {
|
||||
TextView distanceText = (TextView) view.findViewById(R.id.distance);
|
||||
ImageView direction = (ImageView) view.findViewById(R.id.direction);
|
||||
getMyApplication().getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon());
|
||||
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1763,16 +1789,18 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
default:
|
||||
break;
|
||||
}
|
||||
if (!menu.isLandscapeLayout()) {
|
||||
getMapActivity().updateStatusBarColor();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (!menu.isLandscapeLayout() && mapActivity != null) {
|
||||
mapActivity.updateStatusBarColor();
|
||||
}
|
||||
return posY;
|
||||
}
|
||||
|
||||
private int addStatusBarHeightIfNeeded(int res) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (Build.VERSION.SDK_INT >= 21 && mapActivity != null) {
|
||||
// One pixel is needed to fill a thin gap between the status bar and the fragment.
|
||||
return res + AndroidUtils.getStatusBarHeight(getActivity()) - 1;
|
||||
return res + AndroidUtils.getStatusBarHeight(mapActivity) - 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1935,6 +1963,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public OsmandApplication getMyApplication() {
|
||||
if (getActivity() == null) {
|
||||
return null;
|
||||
|
@ -1946,7 +1975,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
final boolean centered) {
|
||||
try {
|
||||
|
||||
if (menu.getLatLon() == null || mapActivity.isActivityDestroyed()) {
|
||||
if (menu.getLatLon() == null || mapActivity == null || mapActivity.isActivityDestroyed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2015,17 +2044,14 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
|
||||
private int dpToPx(float dp) {
|
||||
Resources r = getActivity().getResources();
|
||||
return (int) TypedValue.applyDimension(
|
||||
COMPLEX_UNIT_DIP,
|
||||
dp,
|
||||
r.getDisplayMetrics()
|
||||
);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
return mapActivity != null ? AndroidUtils.dpToPx(mapActivity, dp) : (int) dp;
|
||||
}
|
||||
|
||||
public void updateLocation(boolean centerChanged, boolean locationChanged, boolean compassChanged) {
|
||||
|
|
|
@ -34,8 +34,10 @@ public abstract class MenuTitleController {
|
|||
|
||||
public abstract PointDescription getPointDescription();
|
||||
|
||||
@Nullable
|
||||
public abstract Object getObject();
|
||||
|
||||
@Nullable
|
||||
public abstract MenuController getMenuController();
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
|
@ -12,7 +14,7 @@ public class FavoritePointEditor extends PointEditor {
|
|||
|
||||
public static final String TAG = "FavoritePointEditorFragment";
|
||||
|
||||
public FavoritePointEditor(MapActivity mapActivity) {
|
||||
public FavoritePointEditor(@NonNull MapActivity mapActivity) {
|
||||
super(mapActivity);
|
||||
}
|
||||
|
||||
|
@ -26,7 +28,8 @@ public class FavoritePointEditor extends PointEditor {
|
|||
}
|
||||
|
||||
public void add(LatLon latLon, String title, String originObjectName) {
|
||||
if (latLon == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (latLon == null || mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
isNew = true;
|
||||
|
@ -41,7 +44,8 @@ public class FavoritePointEditor extends PointEditor {
|
|||
}
|
||||
|
||||
public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, boolean autoFill) {
|
||||
if (latLon == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (latLon == null || mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
isNew = true;
|
||||
|
@ -63,7 +67,8 @@ public class FavoritePointEditor extends PointEditor {
|
|||
}
|
||||
|
||||
public void edit(FavouritePoint favorite) {
|
||||
if (favorite == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (favorite == null || mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
isNew = false;
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -16,6 +17,7 @@ import net.osmand.data.FavouritePoint;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
|
@ -25,9 +27,13 @@ import net.osmand.util.Algorithms;
|
|||
|
||||
public class FavoritePointEditorFragment extends PointEditorFragment {
|
||||
|
||||
@Nullable
|
||||
private FavoritePointEditor editor;
|
||||
@Nullable
|
||||
private FavouritePoint favorite;
|
||||
@Nullable
|
||||
private FavoriteGroup group;
|
||||
@Nullable
|
||||
FavouritesDbHelper helper;
|
||||
|
||||
private boolean autoFill;
|
||||
|
@ -35,10 +41,13 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
private int defaultColor;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
helper = getMyApplication().getFavorites();
|
||||
editor = getMapActivity().getContextMenu().getFavoritePointEditor();
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
helper = mapActivity.getMyApplication().getFavorites();
|
||||
editor = mapActivity.getContextMenu().getFavoritePointEditor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,23 +56,32 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
|
||||
defaultColor = getResources().getColor(R.color.color_favorite);
|
||||
|
||||
favorite = editor.getFavorite();
|
||||
group = helper.getGroup(favorite);
|
||||
FavoritePointEditor editor = getFavoritePointEditor();
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
if (editor != null && helper != null) {
|
||||
FavouritePoint favorite = editor.getFavorite();
|
||||
this.favorite = favorite;
|
||||
this.group = helper.getGroup(favorite);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view != null && editor.isNew()) {
|
||||
FavoritePointEditor editor = getFavoritePointEditor();
|
||||
if (view != null && editor != null && editor.isNew()) {
|
||||
Button replaceButton = (Button) view.findViewById(R.id.replace_button);
|
||||
replaceButton.setTextColor(getResources().getColor(!getEditor().isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
replaceButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
replaceButton.setVisibility(View.VISIBLE);
|
||||
replaceButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(FavoriteDialogs.KEY_FAVORITE, favorite);
|
||||
FavoriteDialogs.createReplaceFavouriteDialog(getActivity(), args);
|
||||
args.putSerializable(FavoriteDialogs.KEY_FAVORITE, getFavorite());
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
FavoriteDialogs.createReplaceFavouriteDialog(activity, args);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -71,10 +89,10 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (autoFill){
|
||||
if (autoFill) {
|
||||
|
||||
// String name = favorite.getName() != null && !favorite.getName().isEmpty() ?
|
||||
// favorite.getName() : getString(R.string.favorite_empty_place_name);
|
||||
|
@ -92,19 +110,46 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
return editor;
|
||||
}
|
||||
|
||||
public FavoritePointEditor getFavoritePointEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FavouritePoint getFavorite() {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FavoriteGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public FavouritesDbHelper getHelper() {
|
||||
return helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolbarTitle() {
|
||||
if (editor.isNew()) {
|
||||
return getMapActivity().getResources().getString(R.string.favourites_context_menu_add);
|
||||
} else {
|
||||
return getMapActivity().getResources().getString(R.string.favourites_context_menu_edit);
|
||||
FavoritePointEditor editor = getFavoritePointEditor();
|
||||
if (editor != null) {
|
||||
if (editor.isNew()) {
|
||||
return getString(R.string.favourites_context_menu_add);
|
||||
} else {
|
||||
return getString(R.string.favourites_context_menu_edit);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCategory(String name, int color) {
|
||||
group = helper.getGroup(name);
|
||||
super.setCategory(name, group.color);
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
if (helper != null) {
|
||||
FavoriteGroup group = helper.getGroup(name);
|
||||
this.group = group;
|
||||
super.setCategory(name, group.color);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,18 +157,18 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
return getString(R.string.shared_string_favorites);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void showInstance(final MapActivity mapActivity) {
|
||||
public static void showInstance(@NonNull MapActivity mapActivity) {
|
||||
FavoritePointEditor editor = mapActivity.getContextMenu().getFavoritePointEditor();
|
||||
//int slideInAnim = editor.getSlideInAnimation();
|
||||
//int slideOutAnim = editor.getSlideOutAnimation();
|
||||
|
||||
FavoritePointEditorFragment fragment = new FavoritePointEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commitAllowingStateLoss();
|
||||
if (editor != null) {
|
||||
FavoritePointEditorFragment fragment = new FavoritePointEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showAutoFillInstance(final MapActivity mapActivity, boolean autoFill) {
|
||||
|
@ -134,13 +179,14 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
FavoritePointEditorFragment fragment = new FavoritePointEditorFragment();
|
||||
fragment.autoFill = autoFill;
|
||||
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
if (editor != null) {
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean wasSaved() {
|
||||
return saved;
|
||||
|
@ -148,50 +194,58 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
|
||||
@Override
|
||||
protected void save(final boolean needDismiss) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
point.setDescription(getDescriptionTextValue());
|
||||
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
|
||||
final FavouritePoint favorite = getFavorite();
|
||||
if (favorite != null) {
|
||||
final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(),
|
||||
getNameTextValue(), getCategoryTextValue());
|
||||
point.setDescription(getDescriptionTextValue());
|
||||
AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity());
|
||||
|
||||
if (favorite.getName().equals(point.getName()) &&
|
||||
favorite.getCategory().equals(point.getCategory()) &&
|
||||
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription())) {
|
||||
if (favorite.getName().equals(point.getName()) &&
|
||||
favorite.getCategory().equals(point.getCategory()) &&
|
||||
Algorithms.stringsEqual(favorite.getDescription(), point.getDescription())) {
|
||||
|
||||
if (needDismiss) {
|
||||
dismiss(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (builder != null && !autoFill) {
|
||||
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
|
||||
if (needDismiss) {
|
||||
dismiss(false);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
} else {
|
||||
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
|
||||
return;
|
||||
}
|
||||
|
||||
if (builder != null && !autoFill) {
|
||||
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
} else {
|
||||
doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), needDismiss);
|
||||
}
|
||||
saved = true;
|
||||
}
|
||||
saved = true;
|
||||
}
|
||||
|
||||
private void doSave(FavouritePoint favorite, String name, String category, String description, boolean needDismiss) {
|
||||
if (editor.isNew()) {
|
||||
doAddFavorite(name, category, description);
|
||||
} else {
|
||||
helper.editFavouriteName(favorite, name, category, description);
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
FavoritePointEditor editor = getFavoritePointEditor();
|
||||
if (editor != null && helper != null) {
|
||||
if (editor.isNew()) {
|
||||
doAddFavorite(name, category, description);
|
||||
} else {
|
||||
helper.editFavouriteName(favorite, name, category, description);
|
||||
}
|
||||
}
|
||||
if(getMapActivity() == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
getMapActivity().refreshMap();
|
||||
mapActivity.refreshMap();
|
||||
if (needDismiss) {
|
||||
dismiss(false);
|
||||
}
|
||||
|
||||
MapContextMenu menu = getMapActivity().getContextMenu();
|
||||
MapContextMenu menu = mapActivity.getContextMenu();
|
||||
LatLon latLon = new LatLon(favorite.getLatitude(), favorite.getLongitude());
|
||||
if (menu.getLatLon() != null && menu.getLatLon().equals(latLon)) {
|
||||
menu.update(latLon, favorite.getPointDescription(), favorite);
|
||||
|
@ -199,51 +253,69 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
}
|
||||
|
||||
private void doAddFavorite(String name, String category, String description) {
|
||||
favorite.setName(name);
|
||||
favorite.setCategory(category);
|
||||
favorite.setDescription(description);
|
||||
getMyApplication().getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
|
||||
helper.addFavourite(favorite);
|
||||
OsmandApplication app = getMyApplication();
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
FavouritePoint favorite = getFavorite();
|
||||
if (app != null && favorite != null && helper != null) {
|
||||
favorite.setName(name);
|
||||
favorite.setCategory(category);
|
||||
favorite.setDescription(description);
|
||||
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category);
|
||||
helper.addFavourite(favorite);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void delete(final boolean needDismiss) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(getString(R.string.favourites_remove_dialog_msg, favorite.getName()));
|
||||
builder.setNegativeButton(R.string.shared_string_no, null);
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
helper.deleteFavourite(favorite);
|
||||
saved = true;
|
||||
if (needDismiss) {
|
||||
dismiss(true);
|
||||
} else {
|
||||
getMapActivity().refreshMap();
|
||||
FragmentActivity activity = getActivity();
|
||||
final FavouritePoint favorite = getFavorite();
|
||||
if (activity != null && favorite != null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setMessage(getString(R.string.favourites_remove_dialog_msg, favorite.getName()));
|
||||
builder.setNegativeButton(R.string.shared_string_no, null);
|
||||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
FavouritesDbHelper helper = getHelper();
|
||||
if (helper != null) {
|
||||
helper.deleteFavourite(favorite);
|
||||
saved = true;
|
||||
if (needDismiss) {
|
||||
dismiss(true);
|
||||
} else {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeaderCaption() {
|
||||
return getMapActivity().getResources().getString(R.string.favourites_edit_dialog_title);
|
||||
return getString(R.string.favourites_edit_dialog_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInitValue() {
|
||||
return favorite.getName();
|
||||
FavouritePoint favorite = getFavorite();
|
||||
return favorite != null ? favorite.getName() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategoryInitValue() {
|
||||
return favorite.getCategory().length() == 0 ? getDefaultCategoryName() : favorite.getCategory();
|
||||
FavouritePoint favorite = getFavorite();
|
||||
return favorite == null || favorite.getCategory().length() == 0 ? getDefaultCategoryName() : favorite.getCategory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescriptionInitValue() {
|
||||
return favorite.getDescription();
|
||||
FavouritePoint favorite = getFavorite();
|
||||
return favorite != null ? favorite.getDescription() : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -259,6 +331,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
|
|||
@Override
|
||||
public int getPointColor() {
|
||||
int color = 0;
|
||||
FavoriteGroup group = getGroup();
|
||||
if (group != null) {
|
||||
color = group.color;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ public class MapMarkerEditor extends PointEditor {
|
|||
|
||||
private MapMarker marker;
|
||||
|
||||
public MapMarkerEditor(MapActivity mapActivity) {
|
||||
public MapMarkerEditor(@NonNull MapActivity mapActivity) {
|
||||
super(mapActivity);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ public class MapMarkerEditor extends PointEditor {
|
|||
public void edit(@NonNull MapMarker marker) {
|
||||
this.marker = marker;
|
||||
isNew = false;
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
MapMarkerEditorFragment.showInstance(mapActivity);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@ public class MapMarkerEditorFragment extends PointEditorFragment {
|
|||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
editor = getMapActivity().getContextMenu().getMapMarkerEditor();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
editor = mapActivity != null ? mapActivity.getContextMenu().getMapMarkerEditor() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -132,10 +133,12 @@ public class MapMarkerEditorFragment extends PointEditorFragment {
|
|||
|
||||
public static void showInstance(MapActivity mapActivity) {
|
||||
MapMarkerEditor editor = mapActivity.getContextMenu().getMapMarkerEditor();
|
||||
MapMarkerEditorFragment fragment = new MapMarkerEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null)
|
||||
.commitAllowingStateLoss();
|
||||
if (editor != null) {
|
||||
MapMarkerEditorFragment fragment = new MapMarkerEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null)
|
||||
.commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,11 @@ public abstract class PointEditor {
|
|||
this.mapActivity = mapActivity;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapActivity getMapActivity() {
|
||||
return mapActivity;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return isNew;
|
||||
}
|
||||
|
@ -71,6 +76,7 @@ public abstract class PointEditor {
|
|||
public abstract String getFragmentTag();
|
||||
|
||||
public void hide() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(getFragmentTag());
|
||||
if (fragment != null)
|
||||
|
@ -79,6 +85,7 @@ public abstract class PointEditor {
|
|||
}
|
||||
|
||||
public void setCategory(String name, int color) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
Fragment fragment = mapActivity.getSupportFragmentManager().findFragmentByTag(getFragmentTag());
|
||||
if (fragment != null) {
|
||||
|
|
|
@ -44,8 +44,13 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
|
||||
view = inflater.inflate(R.layout.point_editor_fragment, container, false);
|
||||
|
||||
getEditor().updateLandscapePortrait(requireActivity());
|
||||
getEditor().updateNightMode();
|
||||
PointEditor editor = getEditor();
|
||||
if (editor == null) {
|
||||
return view;
|
||||
}
|
||||
|
||||
editor.updateLandscapePortrait(requireActivity());
|
||||
editor.updateNightMode();
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(getToolbarTitle());
|
||||
|
@ -62,7 +67,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
});
|
||||
|
||||
Button saveButton = (Button) view.findViewById(R.id.save_button);
|
||||
saveButton.setTextColor(getResources().getColor(!getEditor().isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
saveButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -71,7 +76,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
});
|
||||
|
||||
Button cancelButton = (Button) view.findViewById(R.id.cancel_button);
|
||||
cancelButton.setTextColor(getResources().getColor(!getEditor().isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
cancelButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -81,7 +86,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
});
|
||||
|
||||
Button deleteButton = (Button) view.findViewById(R.id.delete_button);
|
||||
deleteButton.setTextColor(getResources().getColor(!getEditor().isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
deleteButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
|
||||
deleteButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -89,39 +94,40 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
});
|
||||
|
||||
if (getEditor().isNew()) {
|
||||
if (editor.isNew()) {
|
||||
deleteButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
deleteButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
view.findViewById(R.id.background_layout).setBackgroundResource(!getEditor().isLight() ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||
view.findViewById(R.id.buttons_layout).setBackgroundResource(!getEditor().isLight() ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||
view.findViewById(R.id.title_view).setBackgroundResource(!getEditor().isLight() ? R.color.bg_color_dark : R.color.bg_color_light);
|
||||
view.findViewById(R.id.description_info_view).setBackgroundResource(!getEditor().isLight() ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||
view.findViewById(R.id.background_layout).setBackgroundResource(!editor.isLight() ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||
view.findViewById(R.id.buttons_layout).setBackgroundResource(!editor.isLight() ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||
view.findViewById(R.id.title_view).setBackgroundResource(!editor.isLight() ? R.color.bg_color_dark : R.color.bg_color_light);
|
||||
view.findViewById(R.id.description_info_view).setBackgroundResource(!editor.isLight() ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
|
||||
|
||||
TextView nameCaption = (TextView) view.findViewById(R.id.name_caption);
|
||||
AndroidUtils.setTextSecondaryColor(view.getContext(), nameCaption, !getEditor().isLight());
|
||||
AndroidUtils.setTextSecondaryColor(view.getContext(), nameCaption, !editor.isLight());
|
||||
nameCaption.setText(getNameCaption());
|
||||
TextView categoryCaption = (TextView) view.findViewById(R.id.category_caption);
|
||||
AndroidUtils.setTextSecondaryColor(view.getContext(), categoryCaption, !getEditor().isLight());
|
||||
AndroidUtils.setTextSecondaryColor(view.getContext(), categoryCaption, !editor.isLight());
|
||||
categoryCaption.setText(getCategoryCaption());
|
||||
|
||||
nameEdit = (EditText) view.findViewById(R.id.name_edit);
|
||||
AndroidUtils.setTextPrimaryColor(view.getContext(), nameEdit, !getEditor().isLight());
|
||||
AndroidUtils.setHintTextSecondaryColor(view.getContext(), nameEdit, !getEditor().isLight());
|
||||
AndroidUtils.setTextPrimaryColor(view.getContext(), nameEdit, !editor.isLight());
|
||||
AndroidUtils.setHintTextSecondaryColor(view.getContext(), nameEdit, !editor.isLight());
|
||||
nameEdit.setText(getNameInitValue());
|
||||
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) view.findViewById(R.id.category_edit);
|
||||
AndroidUtils.setTextPrimaryColor(view.getContext(), categoryEdit, !getEditor().isLight());
|
||||
AndroidUtils.setTextPrimaryColor(view.getContext(), categoryEdit, !editor.isLight());
|
||||
categoryEdit.setText(getCategoryInitValue());
|
||||
categoryEdit.setFocusable(false);
|
||||
categoryEdit.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(final View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
DialogFragment dialogFragment =
|
||||
createSelectCategoryDialog();
|
||||
dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG);
|
||||
DialogFragment dialogFragment = createSelectCategoryDialog();
|
||||
if (dialogFragment != null) {
|
||||
dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -129,8 +135,8 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
});
|
||||
|
||||
final EditText descriptionEdit = (EditText) view.findViewById(R.id.description_edit);
|
||||
AndroidUtils.setTextPrimaryColor(view.getContext(), descriptionEdit, !getEditor().isLight());
|
||||
AndroidUtils.setHintTextSecondaryColor(view.getContext(), descriptionEdit, !getEditor().isLight());
|
||||
AndroidUtils.setTextPrimaryColor(view.getContext(), descriptionEdit, !editor.isLight());
|
||||
AndroidUtils.setHintTextSecondaryColor(view.getContext(), descriptionEdit, !editor.isLight());
|
||||
if (getDescriptionInitValue() != null) {
|
||||
descriptionEdit.setText(getDescriptionInitValue());
|
||||
}
|
||||
|
@ -158,12 +164,20 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
return nameEdit;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected DialogFragment createSelectCategoryDialog() {
|
||||
return SelectCategoryDialogFragment.createInstance(getEditor().getFragmentTag());
|
||||
PointEditor editor = getEditor();
|
||||
if (editor != null) {
|
||||
return SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Drawable getRowIcon(int iconId) {
|
||||
return getIcon(iconId, getEditor().isLight() ? R.color.icon_color : R.color.icon_color_light);
|
||||
PointEditor editor = getEditor();
|
||||
boolean light = editor == null || editor.isLight();
|
||||
return getIcon(iconId, light ? R.color.icon_color : R.color.icon_color_light);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -178,7 +192,8 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (getEditor().isNew()) {
|
||||
PointEditor editor = getEditor();
|
||||
if (editor != null && editor.isNew()) {
|
||||
nameEdit.selectAll();
|
||||
nameEdit.requestFocus();
|
||||
AndroidUtils.softKeyboardDelayed(nameEdit);
|
||||
|
@ -197,7 +212,8 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (!wasSaved() && !getEditor().isNew() && !cancelled) {
|
||||
PointEditor editor = getEditor();
|
||||
if (!wasSaved() && editor != null && !editor.isNew() && !cancelled) {
|
||||
save(false);
|
||||
}
|
||||
super.onDestroyView();
|
||||
|
@ -244,13 +260,15 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
protected abstract void delete(boolean needDismiss);
|
||||
|
||||
static int getResIdFromAttribute(final Context ctx, final int attr) {
|
||||
if (attr == 0)
|
||||
if (attr == 0) {
|
||||
return 0;
|
||||
}
|
||||
final TypedValue typedvalueattr = new TypedValue();
|
||||
ctx.getTheme().resolveAttribute(attr, typedvalueattr, true);
|
||||
return typedvalueattr.resourceId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract PointEditor getEditor();
|
||||
|
||||
public abstract String getToolbarTitle();
|
||||
|
@ -302,11 +320,11 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
|
|||
public abstract String getHeaderCaption();
|
||||
|
||||
public String getNameCaption() {
|
||||
return getMapActivity().getResources().getString(R.string.shared_string_name);
|
||||
return getString(R.string.shared_string_name);
|
||||
}
|
||||
|
||||
public String getCategoryCaption() {
|
||||
return getMapActivity().getResources().getString(R.string.favourites_edit_dialog_category);
|
||||
return getString(R.string.favourites_edit_dialog_category);
|
||||
}
|
||||
|
||||
public abstract String getNameInitValue();
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
public class RtePtEditor extends WptPtEditor {
|
||||
|
||||
public static final String TAG = "RtePtEditorFragment";
|
||||
|
||||
public RtePtEditor(MapActivity mapActivity) {
|
||||
public RtePtEditor(@NonNull MapActivity mapActivity) {
|
||||
super(mapActivity);
|
||||
}
|
||||
|
||||
|
@ -17,11 +19,17 @@ public class RtePtEditor extends WptPtEditor {
|
|||
|
||||
@Override
|
||||
public void showEditorFragment() {
|
||||
RtePtEditorFragment.showInstance(mapActivity);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
RtePtEditorFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showEditorFragment(boolean skipDialog) {
|
||||
RtePtEditorFragment.showInstance(mapActivity, skipDialog);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
RtePtEditorFragment.showInstance(mapActivity, skipDialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.editors;
|
|||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
||||
|
@ -10,48 +11,55 @@ public class RtePtEditorFragment extends WptPtEditorFragment {
|
|||
|
||||
@Override
|
||||
public void assignEditor() {
|
||||
editor = getMapActivity().getContextMenu().getRtePtPointEditor();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
editor = mapActivity != null ? mapActivity.getContextMenu().getRtePtPointEditor() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolbarTitle() {
|
||||
return getMapActivity().getResources().getString(R.string.save_route_point);
|
||||
return getString(R.string.save_route_point);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogFragment createSelectCategoryDialog() {
|
||||
return SelectCategoryDialogFragment.createInstance(getEditor().getFragmentTag());
|
||||
PointEditor editor = getEditor();
|
||||
return editor != null ? SelectCategoryDialogFragment.createInstance(editor.getFragmentTag()) : null;
|
||||
}
|
||||
|
||||
public static void showInstance(final MapActivity mapActivity) {
|
||||
RtePtEditor editor = mapActivity.getContextMenu().getRtePtPointEditor();
|
||||
//int slideInAnim = editor.getSlideInAnimation();
|
||||
//int slideOutAnim = editor.getSlideOutAnimation();
|
||||
if (editor != null) {
|
||||
//int slideInAnim = editor.getSlideInAnimation();
|
||||
//int slideOutAnim = editor.getSlideOutAnimation();
|
||||
|
||||
RtePtEditorFragment fragment = new RtePtEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
RtePtEditorFragment fragment = new RtePtEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showInstance(final MapActivity mapActivity, boolean skipDialog) {
|
||||
RtePtEditor editor = mapActivity.getContextMenu().getRtePtPointEditor();
|
||||
//int slideInAnim = editor.getSlideInAnimation();
|
||||
//int slideOutAnim = editor.getSlideOutAnimation();
|
||||
if (editor != null) {
|
||||
//int slideInAnim = editor.getSlideInAnimation();
|
||||
//int slideOutAnim = editor.getSlideOutAnimation();
|
||||
|
||||
RtePtEditorFragment fragment = new RtePtEditorFragment();
|
||||
fragment.skipDialog = skipDialog;
|
||||
RtePtEditorFragment fragment = new RtePtEditorFragment();
|
||||
fragment.skipDialog = skipDialog;
|
||||
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
//.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim)
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addWpt(GPXUtilities.GPXFile gpx, String description, String name, String category, int color) {
|
||||
wpt = gpx.addRtePt(wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
WptPt wpt = getWpt();
|
||||
this.wpt = wpt != null ? gpx.addRtePt(wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color) : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.plus.mapcontextmenu.editors;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
@ -17,7 +19,7 @@ public class WptPtEditor extends PointEditor {
|
|||
|
||||
public static final String TAG = "WptPtEditorFragment";
|
||||
|
||||
public WptPtEditor(MapActivity mapActivity) {
|
||||
public WptPtEditor(@NonNull MapActivity mapActivity) {
|
||||
super(mapActivity);
|
||||
}
|
||||
|
||||
|
@ -59,7 +61,8 @@ public class WptPtEditor extends PointEditor {
|
|||
}
|
||||
|
||||
public void add(GPXFile gpxFile, LatLon latLon, String title) {
|
||||
if (latLon == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (latLon == null || mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
isNew = true;
|
||||
|
@ -76,7 +79,8 @@ public class WptPtEditor extends PointEditor {
|
|||
}
|
||||
|
||||
public void add(GPXFile gpxFile, LatLon latLon, String title, String categoryName, int categoryColor, boolean skipDialog) {
|
||||
if (latLon == null) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (latLon == null || mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
isNew = true;
|
||||
|
@ -86,13 +90,12 @@ public class WptPtEditor extends PointEditor {
|
|||
mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
|
||||
gpxSelected = selectedGpxFile != null;
|
||||
|
||||
wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(),
|
||||
WptPt wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(),
|
||||
System.currentTimeMillis(), Double.NaN, 0, Double.NaN);
|
||||
|
||||
wpt.name = title;
|
||||
|
||||
if (categoryName != null && !categoryName.isEmpty()) {
|
||||
|
||||
FavouritesDbHelper.FavoriteGroup category = mapActivity.getMyApplication()
|
||||
.getFavorites()
|
||||
.getGroup(categoryName);
|
||||
|
@ -107,12 +110,14 @@ public class WptPtEditor extends PointEditor {
|
|||
} else categoryName = "";
|
||||
|
||||
wpt.category = categoryName;
|
||||
this.wpt = wpt;
|
||||
|
||||
showEditorFragment(skipDialog);
|
||||
}
|
||||
|
||||
public void edit(WptPt wpt) {
|
||||
if (wpt == null) {
|
||||
public void edit(@NonNull WptPt wpt) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null) {
|
||||
return;
|
||||
}
|
||||
isNew = false;
|
||||
|
@ -127,10 +132,16 @@ public class WptPtEditor extends PointEditor {
|
|||
}
|
||||
|
||||
public void showEditorFragment() {
|
||||
WptPtEditorFragment.showInstance(mapActivity);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
WptPtEditorFragment.showInstance(mapActivity);
|
||||
}
|
||||
}
|
||||
|
||||
public void showEditorFragment(boolean skipDialog) {
|
||||
WptPtEditorFragment.showInstance(mapActivity, skipDialog);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
WptPtEditorFragment.showInstance(mapActivity, skipDialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,9 +33,13 @@ import java.util.Map;
|
|||
|
||||
public class WptPtEditorFragment extends PointEditorFragment {
|
||||
|
||||
@Nullable
|
||||
protected WptPtEditor editor;
|
||||
@Nullable
|
||||
protected WptPt wpt;
|
||||
@Nullable
|
||||
private SavingTrackHelper savingTrackHelper;
|
||||
@Nullable
|
||||
private GpxSelectionHelper selectedGpxHelper;
|
||||
|
||||
private boolean saved;
|
||||
|
@ -47,40 +51,54 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
savingTrackHelper = getMapActivity().getMyApplication().getSavingTrackHelper();
|
||||
selectedGpxHelper = getMapActivity().getMyApplication().getSelectedGpxHelper();
|
||||
assignEditor();
|
||||
defaultColor = getResources().getColor(R.color.gpx_color_point);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
savingTrackHelper = app.getSavingTrackHelper();
|
||||
selectedGpxHelper = app.getSelectedGpxHelper();
|
||||
assignEditor();
|
||||
defaultColor = getResources().getColor(R.color.gpx_color_point);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DialogFragment createSelectCategoryDialog() {
|
||||
SelectCategoryDialogFragment selectCategoryDialogFragment = SelectCategoryDialogFragment.createInstance(getEditor().getFragmentTag());
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
selectCategoryDialogFragment.setGpxFile(gpx);
|
||||
selectCategoryDialogFragment.setGpxCategories(categoriesMap);
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
if (editor != null) {
|
||||
SelectCategoryDialogFragment selectCategoryDialogFragment = SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
selectCategoryDialogFragment.setGpxFile(gpx);
|
||||
selectCategoryDialogFragment.setGpxCategories(categoriesMap);
|
||||
}
|
||||
return selectCategoryDialogFragment;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return selectCategoryDialogFragment;
|
||||
}
|
||||
|
||||
protected void assignEditor() {
|
||||
editor = getMapActivity().getContextMenu().getWptPtPointEditor();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
editor = mapActivity.getContextMenu().getWptPtPointEditor();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
wpt = editor.getWptPt();
|
||||
color = wpt.getColor(0);
|
||||
categoriesMap = editor.getGpxFile().getWaypointCategoriesWithColors(false);
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
if (editor != null) {
|
||||
WptPt wpt = editor.getWptPt();
|
||||
color = wpt.getColor(0);
|
||||
this.wpt = wpt;
|
||||
categoriesMap = editor.getGpxFile().getWaypointCategoriesWithColors(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
if (skipDialog) {
|
||||
save(true);
|
||||
}
|
||||
|
@ -89,12 +107,15 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
@Override
|
||||
public void dismiss(boolean includingMenu) {
|
||||
super.dismiss(includingMenu);
|
||||
OnDismissListener listener = editor.getOnDismissListener();
|
||||
if (listener != null) {
|
||||
listener.onDismiss();
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
if (editor != null) {
|
||||
OnDismissListener listener = editor.getOnDismissListener();
|
||||
if (listener != null) {
|
||||
listener.onDismiss();
|
||||
}
|
||||
editor.setNewGpxPointProcessing(false);
|
||||
editor.setOnDismissListener(null);
|
||||
}
|
||||
editor.setNewGpxPointProcessing(false);
|
||||
editor.setOnDismissListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,34 +123,61 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
return editor;
|
||||
}
|
||||
|
||||
public WptPtEditor getWptPtEditor() {
|
||||
return editor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public SavingTrackHelper getSavingTrackHelper() {
|
||||
return savingTrackHelper;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public GpxSelectionHelper getSelectedGpxHelper() {
|
||||
return selectedGpxHelper;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WptPt getWpt() {
|
||||
return wpt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolbarTitle() {
|
||||
if (editor.isNewGpxPointProcessing()) {
|
||||
return getMapActivity().getResources().getString(R.string.save_gpx_waypoint);
|
||||
} else {
|
||||
if (editor.isNew()) {
|
||||
return getMapActivity().getResources().getString(R.string.context_menu_item_add_waypoint);
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
if (editor != null) {
|
||||
if (editor.isNewGpxPointProcessing()) {
|
||||
return getString(R.string.save_gpx_waypoint);
|
||||
} else {
|
||||
return getMapActivity().getResources().getString(R.string.shared_string_edit);
|
||||
if (editor.isNew()) {
|
||||
return getString(R.string.context_menu_item_add_waypoint);
|
||||
} else {
|
||||
return getString(R.string.shared_string_edit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void showInstance(final MapActivity mapActivity) {
|
||||
WptPtEditor editor = mapActivity.getContextMenu().getWptPtPointEditor();
|
||||
WptPtEditorFragment fragment = new WptPtEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
if (editor != null) {
|
||||
WptPtEditorFragment fragment = new WptPtEditorFragment();
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void showInstance(final MapActivity mapActivity, boolean skipDialog) {
|
||||
WptPtEditor editor = mapActivity.getContextMenu().getWptPtPointEditor();
|
||||
WptPtEditorFragment fragment = new WptPtEditorFragment();
|
||||
fragment.skipDialog = skipDialog;
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
if (editor != null) {
|
||||
WptPtEditorFragment fragment = new WptPtEditorFragment();
|
||||
fragment.skipDialog = skipDialog;
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, fragment, editor.getFragmentTag())
|
||||
.addToBackStack(null).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,88 +187,106 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
|
||||
@Override
|
||||
protected void save(final boolean needDismiss) {
|
||||
String name = Algorithms.isEmpty(getNameTextValue()) ? null : getNameTextValue();
|
||||
String category = Algorithms.isEmpty(getCategoryTextValue()) ? null : getCategoryTextValue();
|
||||
String description = Algorithms.isEmpty(getDescriptionTextValue()) ? null : getDescriptionTextValue();
|
||||
if (editor.isNew()) {
|
||||
doAddWpt(name, category, description);
|
||||
} else {
|
||||
doUpdateWpt(name, category, description);
|
||||
}
|
||||
getMapActivity().refreshMap();
|
||||
if (needDismiss) {
|
||||
dismiss(false);
|
||||
}
|
||||
|
||||
MapContextMenu menu = getMapActivity().getContextMenu();
|
||||
|
||||
if (menu.getLatLon() != null && menu.isActive()) {
|
||||
|
||||
LatLon latLon = new LatLon(wpt.getLatitude(), wpt.getLongitude());
|
||||
|
||||
if (menu.getLatLon().equals(latLon)) {
|
||||
menu.update(latLon, new WptLocationPoint(wpt).getPointDescription(getMapActivity()), wpt);
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
WptPt wpt = getWpt();
|
||||
if (mapActivity != null && editor != null && wpt != null) {
|
||||
String name = Algorithms.isEmpty(getNameTextValue()) ? null : getNameTextValue();
|
||||
String category = Algorithms.isEmpty(getCategoryTextValue()) ? null : getCategoryTextValue();
|
||||
String description = Algorithms.isEmpty(getDescriptionTextValue()) ? null : getDescriptionTextValue();
|
||||
if (editor.isNew()) {
|
||||
doAddWpt(name, category, description);
|
||||
} else {
|
||||
doUpdateWpt(name, category, description);
|
||||
}
|
||||
mapActivity.refreshMap();
|
||||
if (needDismiss) {
|
||||
dismiss(false);
|
||||
}
|
||||
}
|
||||
|
||||
saved = true;
|
||||
MapContextMenu menu = mapActivity.getContextMenu();
|
||||
if (menu.getLatLon() != null && menu.isActive()) {
|
||||
LatLon latLon = new LatLon(wpt.getLatitude(), wpt.getLongitude());
|
||||
if (menu.getLatLon().equals(latLon)) {
|
||||
menu.update(latLon, new WptLocationPoint(wpt).getPointDescription(mapActivity), wpt);
|
||||
}
|
||||
}
|
||||
saved = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
|
||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
helper.runSynchronization(group);
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
helper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doAddWpt(String name, String category, String description) {
|
||||
wpt.name = name;
|
||||
wpt.category = category;
|
||||
wpt.desc = description;
|
||||
if (color != 0) {
|
||||
wpt.setColor(color);
|
||||
} else {
|
||||
wpt.removeColor();
|
||||
}
|
||||
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
if (!editor.isGpxSelected()) {
|
||||
selectedGpxHelper.setGpxFileToDisplay(gpx);
|
||||
}
|
||||
WptPt wpt = getWpt();
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
if (wpt != null && editor != null) {
|
||||
wpt.name = name;
|
||||
wpt.category = category;
|
||||
wpt.desc = description;
|
||||
if (color != 0) {
|
||||
wpt.setColor(color);
|
||||
} else {
|
||||
addWpt(gpx, description, name, category, color);
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
wpt.removeColor();
|
||||
}
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
|
||||
GpxSelectionHelper selectedGpxHelper = getSelectedGpxHelper();
|
||||
if (gpx != null && savingTrackHelper != null && selectedGpxHelper != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
this.wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
if (!editor.isGpxSelected()) {
|
||||
selectedGpxHelper.setGpxFileToDisplay(gpx);
|
||||
}
|
||||
} else {
|
||||
addWpt(gpx, description, name, category, color);
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
syncGpx(gpx);
|
||||
}
|
||||
syncGpx(gpx);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addWpt(GPXFile gpx, String description, String name, String category, int color) {
|
||||
wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
syncGpx(gpx);
|
||||
WptPt wpt = getWpt();
|
||||
if (wpt != null) {
|
||||
this.wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
syncGpx(gpx);
|
||||
}
|
||||
}
|
||||
|
||||
private void doUpdateWpt(String name, String category, String description) {
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
if (!editor.isGpxSelected()) {
|
||||
selectedGpxHelper.setGpxFileToDisplay(gpx);
|
||||
WptPt wpt = getWpt();
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
|
||||
GpxSelectionHelper selectedGpxHelper = getSelectedGpxHelper();
|
||||
if (wpt != null && editor != null && savingTrackHelper != null && selectedGpxHelper != null) {
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
if (!editor.isGpxSelected()) {
|
||||
selectedGpxHelper.setGpxFileToDisplay(gpx);
|
||||
}
|
||||
} else {
|
||||
gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
} else {
|
||||
gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(),
|
||||
System.currentTimeMillis(), description, name, category, color);
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
syncGpx(gpx);
|
||||
}
|
||||
syncGpx(gpx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,23 +298,30 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
savingTrackHelper.deletePointData(wpt);
|
||||
} else {
|
||||
gpx.deleteWptPt(wpt);
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
WptPt wpt = getWpt();
|
||||
WptPtEditor editor = getWptPtEditor();
|
||||
SavingTrackHelper savingTrackHelper = getSavingTrackHelper();
|
||||
if (wpt != null && editor != null && savingTrackHelper != null) {
|
||||
GPXFile gpx = editor.getGpxFile();
|
||||
if (gpx != null) {
|
||||
if (gpx.showCurrentTrack) {
|
||||
savingTrackHelper.deletePointData(wpt);
|
||||
} else {
|
||||
gpx.deleteWptPt(wpt);
|
||||
new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
syncGpx(gpx);
|
||||
}
|
||||
syncGpx(gpx);
|
||||
saved = true;
|
||||
}
|
||||
saved = true;
|
||||
|
||||
if (needDismiss) {
|
||||
dismiss(true);
|
||||
} else {
|
||||
getMapActivity().refreshMap();
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -271,22 +344,22 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
|
||||
@Override
|
||||
public String getHeaderCaption() {
|
||||
return getMapActivity().getResources().getString(R.string.shared_string_waypoint);
|
||||
return getString(R.string.shared_string_waypoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameInitValue() {
|
||||
return wpt.name;
|
||||
return wpt != null ? wpt.name : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategoryInitValue() {
|
||||
return Algorithms.isEmpty(wpt.category) ? "" : wpt.category;
|
||||
return wpt == null || Algorithms.isEmpty(wpt.category) ? "" : wpt.category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescriptionInitValue() {
|
||||
return wpt.desc;
|
||||
return wpt != null ? wpt.desc : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.GeocodingLookupService.OnAddressLookupResult;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
|
||||
|
@ -110,8 +111,11 @@ public class FavoriteAction extends QuickAction {
|
|||
}
|
||||
|
||||
private void addFavorite(MapActivity mapActivity, LatLon latLon, String title, boolean autoFill) {
|
||||
mapActivity.getContextMenu().getFavoritePointEditor().add(latLon, title, "",
|
||||
getParams().get(KEY_CATEGORY_NAME), Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill);
|
||||
FavoritePointEditor favoritePointEditor = mapActivity.getContextMenu().getFavoritePointEditor();
|
||||
if (favoritePointEditor != null) {
|
||||
favoritePointEditor.add(latLon, title, "", getParams().get(KEY_CATEGORY_NAME),
|
||||
Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,14 +52,18 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener {
|
|||
LatLon latLon = contextMenu.getLatLon();
|
||||
if (pointDescription.isWpt()) {
|
||||
WptPtEditor editor = activity.getContextMenu().getWptPtPointEditor();
|
||||
editor.setOnDismissListener(AddGpxPointBottomSheetHelper.this);
|
||||
editor.setNewGpxPointProcessing(true);
|
||||
editor.add(gpx, latLon, titleText);
|
||||
if (editor != null) {
|
||||
editor.setOnDismissListener(AddGpxPointBottomSheetHelper.this);
|
||||
editor.setNewGpxPointProcessing(true);
|
||||
editor.add(gpx, latLon, titleText);
|
||||
}
|
||||
} else if (pointDescription.isRte()) {
|
||||
RtePtEditor editor = activity.getContextMenu().getRtePtPointEditor();
|
||||
editor.setOnDismissListener(AddGpxPointBottomSheetHelper.this);
|
||||
editor.setNewGpxPointProcessing(true);
|
||||
editor.add(gpx, latLon, titleText);
|
||||
if (editor != null) {
|
||||
editor.setOnDismissListener(AddGpxPointBottomSheetHelper.this);
|
||||
editor.setNewGpxPointProcessing(true);
|
||||
editor.add(gpx, latLon, titleText);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue