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