Show address searching dialog while adding target point

This commit is contained in:
Alexey Kulish 2015-12-11 19:23:43 +03:00
parent 4fc1b11058
commit cf9809c946
3 changed files with 40 additions and 9 deletions

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapcontextmenu;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
@ -57,6 +58,8 @@ public class MapContextMenu extends MenuTitleController {
private int favActionIconId;
private MenuAction searchDoneAction;
@Override
public MapActivity getMapActivity() {
return mapActivity;
@ -333,10 +336,19 @@ public class MapContextMenu extends MenuTitleController {
}
@Override
public void refreshMenuTitle() {
public void onSearchAddressDone() {
WeakReference<MapContextMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null)
fragmentRef.get().refreshTitle();
if (searchDoneAction != null) {
if (searchDoneAction.dlg != null) {
searchDoneAction.dlg.dismiss();
searchDoneAction.dlg = null;
}
searchDoneAction.run();
searchDoneAction = null;
}
}
public WeakReference<MapContextMenuFragment> findMenuFragment() {
@ -406,8 +418,22 @@ public class MapContextMenu extends MenuTitleController {
if (pointDescription.isDestination()) {
mapActivity.getMapActions().editWaypoints();
} else {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
pointDescription);
MenuAction addAsTargetAction = new MenuAction() {
@Override
public void run() {
mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(),
pointDescription);
}
};
if (searchingAddress) {
addAsTargetAction.dlg = ProgressDialog.show(mapActivity,
"",
addressNotKnownStr);
searchDoneAction = addAsTargetAction;
} else {
addAsTargetAction.run();
}
}
close();
}
@ -668,4 +694,8 @@ public class MapContextMenu extends MenuTitleController {
}
});
}
private abstract class MenuAction implements Runnable {
protected ProgressDialog dlg;
}
}

View file

@ -23,6 +23,7 @@ public abstract class MenuTitleController {
protected Drawable secondLineTypeIcon;
protected String streetStr = "";
protected String addressNotKnownStr;
protected boolean searchingAddress;
public abstract MapActivity getMapActivity();
@ -131,6 +132,7 @@ public abstract class MenuTitleController {
}
protected void acquireStreetName() {
searchingAddress = true;
Location ll = new Location("");
ll.setLatitude(getLatLon().getLatitude());
ll.setLongitude(getLatLon().getLongitude());
@ -183,9 +185,10 @@ public abstract class MenuTitleController {
nameStr = streetStr;
getPointDescription().setName(nameStr);
}
searchingAddress = false;
getMapActivity().runOnUiThread(new Runnable() {
public void run() {
refreshMenuTitle();
onSearchAddressDone();
}
});
}
@ -195,12 +198,14 @@ public abstract class MenuTitleController {
@Override
public boolean isCancelled() {
searchingAddress = false;
return false;
}
});
}
protected abstract void refreshMenuTitle();
protected void onSearchAddressDone() {
}
}

View file

@ -73,10 +73,6 @@ public class MapMultiSelectionMenu extends BaseMenuController {
return controller;
}
@Override
protected void refreshMenuTitle() {
}
@Override
protected boolean needStreetName() {
return false;