Merge pull request #1506 from GaidamakUA/iss1500

issue #1500, POI dialog fix
This commit is contained in:
vshcherb 2015-07-28 13:46:39 +02:00
commit 4464d8f2cb

View file

@ -29,14 +29,13 @@ import android.widget.TableLayout;
import android.widget.TableRow; import android.widget.TableRow;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.MapRenderingTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo; import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.EntityParser;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings.OSMTagKey; import net.osmand.osm.edit.OSMSettings.OSMTagKey;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
@ -62,7 +61,7 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
public class EditingPOIDialogProvider implements DialogProvider { public class EditingPOIDialogProvider implements DialogProvider {
private final Activity activity; private final Activity activity;
private final OsmEditingPlugin plugin; private final OsmEditingPlugin plugin;
private OpenstreetmapUtil openstreetmapUtil; private OpenstreetmapUtil openstreetmapUtil;
@ -86,7 +85,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
public static final int DIALOG_PLUGIN = 600; public static final int DIALOG_PLUGIN = 600;
private static final int DIALOG_CREATE_POI = DIALOG_PLUGIN + 0; private static final int DIALOG_CREATE_POI = DIALOG_PLUGIN + 0;
private static final int DIALOG_EDIT_POI = DIALOG_PLUGIN + 1; private static final int DIALOG_EDIT_POI = DIALOG_PLUGIN + 1;
protected static final int DIALOG_SUB_CATEGORIES = DIALOG_PLUGIN + 2; protected static final int DIALOG_SUB_CATEGORIES = DIALOG_PLUGIN + 2;
protected static final int DIALOG_POI_TYPES = DIALOG_PLUGIN + 3; protected static final int DIALOG_POI_TYPES = DIALOG_PLUGIN + 3;
private static final int DIALOG_DELETE_POI = DIALOG_PLUGIN + 4; private static final int DIALOG_DELETE_POI = DIALOG_PLUGIN + 4;
private static final int DIALOG_OPENING_HOURS = DIALOG_PLUGIN + 5; private static final int DIALOG_OPENING_HOURS = DIALOG_PLUGIN + 5;
@ -99,12 +98,12 @@ public class EditingPOIDialogProvider implements DialogProvider {
private MapPoiTypes poiTypes; private MapPoiTypes poiTypes;
private boolean isLocalEdit; private boolean isLocalEdit;
private Map<String, PoiType> allTranslatedSubTypes; private Map<String, PoiType> allTranslatedSubTypes;
public EditingPOIDialogProvider(MapActivity uiContext, OsmEditingPlugin plugin) { public EditingPOIDialogProvider(MapActivity uiContext, OsmEditingPlugin plugin) {
this.activity = uiContext; this.activity = uiContext;
this.plugin = plugin; this.plugin = plugin;
} }
private void prepareProvider() { private void prepareProvider() {
@ -121,10 +120,10 @@ public class EditingPOIDialogProvider implements DialogProvider {
} else { } else {
isLocalEdit = false; isLocalEdit = false;
this.openstreetmapUtil = new OpenstreetmapRemoteUtil(activity); this.openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
this.openstreetmapUtilToLoad = openstreetmapUtil; this.openstreetmapUtilToLoad = openstreetmapUtil;
} }
} }
public void showEditDialog(final Amenity editA){ public void showEditDialog(final Amenity editA){
prepareProvider(); prepareProvider();
new AsyncTask<Void, Void, Node>() { new AsyncTask<Void, Void, Node>() {
@ -133,7 +132,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
protected Node doInBackground(Void... params) { protected Node doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadNode(editA); return openstreetmapUtilToLoad.loadNode(editA);
} }
protected void onPostExecute(Node n) { protected void onPostExecute(Node n) {
if(n != null){ if(n != null){
showPOIDialog(DIALOG_EDIT_POI, n, editA); showPOIDialog(DIALOG_EDIT_POI, n, editA);
@ -141,43 +140,43 @@ public class EditingPOIDialogProvider implements DialogProvider {
AccessibleToast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show(); AccessibleToast.makeText(activity, activity.getString(R.string.poi_error_poi_not_found), Toast.LENGTH_SHORT).show();
} }
}; };
}.execute(new Void[0]); }.execute(new Void[0]);
} }
public void showCreateDialog(double latitude, double longitude){ public void showCreateDialog(double latitude, double longitude){
prepareProvider(); prepareProvider();
Node n = new Node(latitude, longitude, -1); Node n = new Node(latitude, longitude, -1);
showPOIDialog(DIALOG_CREATE_POI, n, null); showPOIDialog(DIALOG_CREATE_POI, n, null);
} }
private void showPOIDialog(int dialogID, Node n, Amenity a) { private void showPOIDialog(int dialogID, Node node, Amenity amenity) {
Amenity am; Amenity localAmenity;
if(a == null) { if(amenity == null) {
am = new Amenity(); localAmenity = new Amenity();
am.setType(poiTypes.getOtherPoiCategory()); localAmenity.setType(poiTypes.getOtherPoiCategory());
am.setSubType(""); localAmenity.setSubType("");
am.setAdditionalInfo(OSMTagKey.OPENING_HOURS.getValue(), ""); localAmenity.setAdditionalInfo(OSMTagKey.OPENING_HOURS.getValue(), "");
} else { } else {
am = new Amenity(); localAmenity = new Amenity();
am.copyNames(a); localAmenity.copyNames(amenity);
am.setType(a.getType()); localAmenity.setType(amenity.getType());
am.setSubType(a.getSubType()); localAmenity.setSubType(amenity.getSubType());
am.setAdditionalInfo(a.getAdditionalInfo()); localAmenity.setAdditionalInfo(amenity.getAdditionalInfo());
} }
// Amenity a = EntityParser.parseAmenity(n, n.getTags(), type, subType, MapRenderingTypes.getDefault()); // Amenity amenity = EntityParser.parseAmenity(node, node.getTags(), type, subType, MapRenderingTypes.getDefault());
dialogBundle.putSerializable(KEY_AMENITY, a); dialogBundle.putSerializable(KEY_AMENITY, localAmenity);
dialogBundle.putSerializable(KEY_AMENITY_NODE, n); dialogBundle.putSerializable(KEY_AMENITY_NODE, node);
createPOIDialog(dialogID, dialogBundle).show(); createPOIDialog(dialogID, dialogBundle).show();
} }
public void showDeleteDialog(final Amenity a){ public void showDeleteDialog(final Amenity a){
prepareProvider(); prepareProvider();
new AsyncTask<Void, Void, Node>() { new AsyncTask<Void, Void, Node>() {
protected Node doInBackground(Void[] params) { protected Node doInBackground(Void[] params) {
return openstreetmapUtil.loadNode(a); return openstreetmapUtil.loadNode(a);
}; };
protected void onPostExecute(Node n) { protected void onPostExecute(Node n) {
if(n == null){ if(n == null){
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show();
@ -189,13 +188,13 @@ public class EditingPOIDialogProvider implements DialogProvider {
}; };
}.execute(new Void[0]); }.execute(new Void[0]);
} }
private void prepareDeleteDialog(Dialog dlg, Bundle args) { private void prepareDeleteDialog(Dialog dlg, Bundle args) {
Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
dlg.setTitle(MessageFormat.format(this.activity.getResources().getString(R.string.poi_remove_confirm_template), dlg.setTitle(MessageFormat.format(this.activity.getResources().getString(R.string.poi_remove_confirm_template),
OsmAndFormatter.getPoiStringWithoutType(a, settings.MAP_PREFERRED_LOCALE.get()))); OsmAndFormatter.getPoiStringWithoutType(a, settings.MAP_PREFERRED_LOCALE.get())));
} }
private Dialog createDeleteDialog(final Bundle args) { private Dialog createDeleteDialog(final Bundle args) {
Builder builder = new AlertDialog.Builder(activity); Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.poi_remove_title); builder.setTitle(R.string.poi_remove_title);
@ -222,20 +221,20 @@ public class EditingPOIDialogProvider implements DialogProvider {
String c = comment.getText().toString(); String c = comment.getText().toString();
commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c,
closeChangeset == null ? false : closeChangeset.isSelected(), new Runnable() { closeChangeset == null ? false : closeChangeset.isSelected(), new Runnable() {
@Override @Override
public void run() { public void run() {
if (isLocalEdit) { if (isLocalEdit) {
AccessibleToast.makeText( AccessibleToast.makeText(
activity,R.string.osm_changes_added_to_local_edits, activity,R.string.osm_changes_added_to_local_edits,
Toast.LENGTH_LONG).show(); Toast.LENGTH_LONG).show();
} else { } else {
AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG).show();
} }
if(activity instanceof MapActivity){ if(activity instanceof MapActivity){
((MapActivity) activity).getMapView().refreshMap(true); ((MapActivity) activity).getMapView().refreshMap(true);
} }
} }
}); });
} }
}); });
return builder.create(); return builder.create();
@ -260,28 +259,28 @@ public class EditingPOIDialogProvider implements DialogProvider {
layout.setVisibility(View.GONE); layout.setVisibility(View.GONE);
updateType(a); updateType(a);
} }
private void addTagValueRow(final Node n, final TableLayout layout, String tg, String vl) { private void addTagValueRow(final Node n, final TableLayout layout, String tg, String vl) {
final TableRow newTagRow = new TableRow(activity); final TableRow newTagRow = new TableRow(activity);
TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); TableRow.LayoutParams tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.leftMargin = 5; tlp.leftMargin = 5;
tlp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; tlp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
newTagRow.setLayoutParams(tlp); newTagRow.setLayoutParams(tlp);
final AutoCompleteTextView tag = new AutoCompleteTextView(activity); final AutoCompleteTextView tag = new AutoCompleteTextView(activity);
final AutoCompleteTextView value = new AutoCompleteTextView(activity); final AutoCompleteTextView value = new AutoCompleteTextView(activity);
final Button delete = new Button(activity); final Button delete = new Button(activity);
tag.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
value.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
tag.setLayoutParams(tlp);
if(tg != null) {
tag.setText(tg);
} else {
tag.setHint("Tag");
}
final Set<String> tagKeys = new TreeSet<String>(); tag.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
value.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
tag.setLayoutParams(tlp);
if(tg != null) {
tag.setText(tg);
} else {
tag.setHint("Tag");
}
final Set<String> tagKeys = new TreeSet<String>();
for (OSMTagKey t : OSMTagKey.values()) { for (OSMTagKey t : OSMTagKey.values()) {
if ((t != OSMTagKey.NAME) && (t != OSMTagKey.OPENING_HOURS) && (t != OSMTagKey.PHONE) if ((t != OSMTagKey.NAME) && (t != OSMTagKey.OPENING_HOURS) && (t != OSMTagKey.PHONE)
&& (t != OSMTagKey.WEBSITE)) { && (t != OSMTagKey.WEBSITE)) {
@ -289,9 +288,9 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
} }
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, tagKeys.toArray()); ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, tagKeys.toArray());
tag.setAdapter(adapter); tag.setAdapter(adapter);
tag.setThreshold(1); tag.setThreshold(1);
tag.setOnClickListener(new View.OnClickListener() { tag.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Builder builder = new AlertDialog.Builder(activity); Builder builder = new AlertDialog.Builder(activity);
@ -301,31 +300,31 @@ public class EditingPOIDialogProvider implements DialogProvider {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
tag.setText(tags[which]); tag.setText(tags[which]);
} }
}); });
builder.create(); builder.create();
builder.show(); builder.show();
} }
}); });
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT); tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.FILL_PARENT);
tlp.leftMargin = 5; tlp.leftMargin = 5;
tlp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; tlp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
value.setLayoutParams(tlp); value.setLayoutParams(tlp);
if(vl != null) { if(vl != null) {
value.setText(vl); value.setText(vl);
} else { } else {
value.setHint("Value"); value.setHint("Value");
} }
Set<String> subCategories = new LinkedHashSet<String>(); Set<String> subCategories = new LinkedHashSet<String>();
// could be osm values // could be osm values
// for (String s : poiTypes.getAllTranslatedNames().keySet()) { // for (String s : poiTypes.getAllTranslatedNames().keySet()) {
// if (!subCategories.contains(s)) { // if (!subCategories.contains(s)) {
// subCategories.add(s); // subCategories.add(s);
// } // }
// } ; // } ;
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.toArray()); ArrayAdapter<Object> valueAdapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, subCategories.toArray());
value.setThreshold(1); value.setThreshold(1);
value.setAdapter(valueAdapter); value.setAdapter(valueAdapter);
value.addTextChangedListener(new TextWatcher() { value.addTextChangedListener(new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
@ -343,26 +342,26 @@ public class EditingPOIDialogProvider implements DialogProvider {
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
} }
}); });
tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT); tlp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT);
tlp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; tlp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
tlp.rightMargin = 5; tlp.rightMargin = 5;
delete.setLayoutParams(tlp); delete.setLayoutParams(tlp);
delete.setText("X"); delete.setText("X");
delete.setOnClickListener(new View.OnClickListener() { delete.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
layout.removeView(newTagRow); layout.removeView(newTagRow);
layout.invalidate(); layout.invalidate();
n.removeTag(tag.getText().toString()); n.removeTag(tag.getText().toString());
} }
}); });
newTagRow.addView(tag); newTagRow.addView(tag);
newTagRow.addView(value); newTagRow.addView(value);
newTagRow.addView(delete); newTagRow.addView(delete);
layout.addView(newTagRow); layout.addView(newTagRow);
layout.invalidate(); layout.invalidate();
} }
private Builder createPOIDialog(final int dialogID, Bundle args) { private Builder createPOIDialog(final int dialogID, Bundle args) {
final View view = activity.getLayoutInflater().inflate(R.layout.editing_poi, null); final View view = activity.getLayoutInflater().inflate(R.layout.editing_poi, null);
final Builder dlg = new Builder(activity); final Builder dlg = new Builder(activity);
@ -377,7 +376,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
//dlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);; //dlg.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);;
nameText = ((EditText)view.findViewById(R.id.Name)); nameText = ((EditText)view.findViewById(R.id.Name));
openingHours = ((EditText)view.findViewById(R.id.OpeningHours)); openingHours = ((EditText)view.findViewById(R.id.OpeningHours));
typeText = ((AutoCompleteTextView)view.findViewById(R.id.Type)); typeText = ((AutoCompleteTextView)view.findViewById(R.id.Type));
@ -405,64 +404,64 @@ public class EditingPOIDialogProvider implements DialogProvider {
}); });
linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance()); linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); final Amenity amenity = (Amenity) args.getSerializable(KEY_AMENITY);
final Node n = (Node) args.getSerializable(KEY_AMENITY_NODE); final Node node = (Node) args.getSerializable(KEY_AMENITY_NODE);
dlg.setNegativeButton(R.string.shared_string_cancel, null); dlg.setNegativeButton(R.string.shared_string_cancel, null);
dlg.setPositiveButton( dlg.setPositiveButton(
isLocalEdit ? R.string.shared_string_save : isLocalEdit ? R.string.shared_string_save :
R.string.default_buttons_commit, new DialogInterface.OnClickListener() { R.string.default_buttons_commit, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Resources resources = view.getResources(); Resources resources = view.getResources();
final String msg = n.getId() == -1 ? resources.getString(R.string.poi_action_add) : resources final String msg = node.getId() == -1 ? resources.getString(R.string.poi_action_add) : resources
.getString(R.string.poi_action_change); .getString(R.string.poi_action_change);
OsmPoint.Action action = n.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY; OsmPoint.Action action = node.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
String subType = typeText.getText().toString().trim().toLowerCase(); String subType = typeText.getText().toString().trim().toLowerCase();
if (allTranslatedSubTypes.get(subType) != null) { if (allTranslatedSubTypes.get(subType) != null) {
PoiType pt = allTranslatedSubTypes.get(subType); PoiType pt = allTranslatedSubTypes.get(subType);
n.putTag(pt.getOsmTag(), pt.getOsmValue()); node.putTag(pt.getOsmTag(), pt.getOsmValue());
if (pt.getOsmTag2() != null) { if (pt.getOsmTag2() != null) {
n.putTag(pt.getOsmTag2(), pt.getOsmValue2()); node.putTag(pt.getOsmTag2(), pt.getOsmValue2());
} }
} else { } else {
n.putTag(a.getType().getDefaultTag(), subType); node.putTag(amenity.getType().getDefaultTag(), subType);
} }
String name = nameText.getText().toString(); String name = nameText.getText().toString();
if(name.length() > 0) { if(name.length() > 0) {
n.putTag(OSMTagKey.NAME.getValue(), name); node.putTag(OSMTagKey.NAME.getValue(), name);
} }
if (openingHours.getText().toString().length() == 0) { if (openingHours.getText().toString().length() == 0) {
n.removeTag(OSMTagKey.OPENING_HOURS.getValue()); node.removeTag(OSMTagKey.OPENING_HOURS.getValue());
} else { } else {
n.putTag(OSMTagKey.OPENING_HOURS.getValue(), openingHours.getText().toString()); node.putTag(OSMTagKey.OPENING_HOURS.getValue(), openingHours.getText().toString());
} }
String website = websiteText.getText().toString(); String website = websiteText.getText().toString();
if (website.length() > 0 ){ if (website.length() > 0 ){
n.putTag(OSMTagKey.WEBSITE.getValue(),website); node.putTag(OSMTagKey.WEBSITE.getValue(), website);
} else { } else {
n.removeTag(OSMTagKey.WEBSITE.getValue()); node.removeTag(OSMTagKey.WEBSITE.getValue());
} }
String phone = phoneText.getText().toString(); String phone = phoneText.getText().toString();
if (phone.length() > 0 ){ if (phone.length() > 0 ){
n.putTag(OSMTagKey.PHONE.getValue(),phone); node.putTag(OSMTagKey.PHONE.getValue(), phone);
} else { } else {
n.removeTag(OSMTagKey.PHONE.getValue()); node.removeTag(OSMTagKey.PHONE.getValue());
} }
String str = streetNameText.getText().toString(); String str = streetNameText.getText().toString();
if (str .length() > 0 ){ if (str .length() > 0 ){
n.putTag(OSMTagKey.ADDR_STREET.getValue(),str); node.putTag(OSMTagKey.ADDR_STREET.getValue(), str);
} else { } else {
n.removeTag(OSMTagKey.ADDR_STREET.getValue()); node.removeTag(OSMTagKey.ADDR_STREET.getValue());
} }
String hno = hnoText.getText().toString(); String hno = hnoText.getText().toString();
if (hno .length() > 0 ){ if (hno .length() > 0 ){
n.putTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),hno); node.putTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue(), hno);
} else { } else {
n.removeTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue()); node.removeTag(OSMTagKey.ADDR_HOUSE_NUMBER.getValue());
} }
commitNode(action, n, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), closeChange.isSelected(), commitNode(action, node, openstreetmapUtil.getEntityInfo(), commentText.getText().toString(), closeChange.isSelected(),
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
if (isLocalEdit) { if (isLocalEdit) {
AccessibleToast.makeText( AccessibleToast.makeText(
@ -481,15 +480,15 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
activity.removeDialog(dialogID); activity.removeDialog(dialogID);
} }
}); });
} }
}); });
preparePOIDialog(view, args); preparePOIDialog(view, args);
attachListeners(view, a, n); attachListeners(view, amenity, node);
updateOsmTagValue(a); updateOsmTagValue(amenity);
return dlg; return dlg;
} }
private void updateOsmTagValue(final Amenity a) { private void updateOsmTagValue(final Amenity a) {
String subType = typeText.getText().toString().trim().toLowerCase(); String subType = typeText.getText().toString().trim().toLowerCase();
String s = "OSM "; String s = "OSM ";
@ -556,9 +555,9 @@ public class EditingPOIDialogProvider implements DialogProvider {
activity.showDialog(DIALOG_POI_TYPES); activity.showDialog(DIALOG_POI_TYPES);
} }
}); });
final Button advancedModeButton = ((Button)dlg.findViewById(R.id.advancedMode)); final Button advancedModeButton = ((Button)dlg.findViewById(R.id.advancedMode));
advancedModeButton.setOnClickListener(new View.OnClickListener() { advancedModeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final TableLayout layout = ((TableLayout) dlg.findViewById(R.id.advancedModeTable)); final TableLayout layout = ((TableLayout) dlg.findViewById(R.id.advancedModeTable));
@ -591,7 +590,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
} }
}); });
} }
private void showSubCategory(Amenity a) { private void showSubCategory(Amenity a) {
@ -628,19 +627,19 @@ public class EditingPOIDialogProvider implements DialogProvider {
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue()); subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
} }
} }
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview, ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(activity, R.layout.list_textview,
subCategories.keySet().toArray()); subCategories.keySet().toArray());
typeText.setAdapter(adapter); typeText.setAdapter(adapter);
return subCategories; return subCategories;
} }
private void updateType(Amenity a){ private void updateType(Amenity a){
typeText.setText(a.getSubType()); typeText.setText(a.getSubType());
typeButton.setText(a.getType().getTranslation()); typeButton.setText(a.getType().getTranslation());
updateSubTypesAdapter(a.getType()); updateSubTypesAdapter(a.getType());
updateOsmTagValue(a); updateOsmTagValue(a);
} }
private Dialog createOpenHoursDlg(){ private Dialog createOpenHoursDlg(){
OpeningHours time = OpeningHoursParser.parseOpenedHours(openingHours.getText().toString()); OpeningHours time = OpeningHoursParser.parseOpenedHours(openingHours.getText().toString());
@ -648,7 +647,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
AccessibleToast.makeText(activity, activity.getString(R.string.opening_hours_not_supported), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, activity.getString(R.string.opening_hours_not_supported), Toast.LENGTH_LONG).show();
return null; return null;
} }
List<BasicOpeningHourRule> simple = null; List<BasicOpeningHourRule> simple = null;
if(time != null){ if(time != null){
simple = new ArrayList<BasicOpeningHourRule>(); simple = new ArrayList<BasicOpeningHourRule>();
@ -661,7 +660,7 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
} }
} }
Builder builder = new AlertDialog.Builder(activity); Builder builder = new AlertDialog.Builder(activity);
final OpeningHoursView v = new OpeningHoursView(activity); final OpeningHoursView v = new OpeningHoursView(activity);
builder.setView(v.createOpeningHoursEditView(simple)); builder.setView(v.createOpeningHoursEditView(simple));
@ -681,11 +680,11 @@ public class EditingPOIDialogProvider implements DialogProvider {
}); });
return builder.create(); return builder.create();
} }
public void commitNode(final OsmPoint.Action action, final Node n, final EntityInfo info, final String comment, public void commitNode(final OsmPoint.Action action, final Node n, final EntityInfo info, final String comment,
final boolean closeChangeSet, final boolean closeChangeSet,
final Runnable successAction) { final Runnable successAction) {
if (info == null && OsmPoint.Action.CREATE != action) { if (info == null && OsmPoint.Action.CREATE != action) {
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
return; return;
@ -717,60 +716,60 @@ public class EditingPOIDialogProvider implements DialogProvider {
public Dialog onCreateDialog(int id) { public Dialog onCreateDialog(int id) {
Bundle args = dialogBundle; Bundle args = dialogBundle;
switch (id) { switch (id) {
case DIALOG_DELETE_POI: case DIALOG_DELETE_POI:
return createDeleteDialog(args); return createDeleteDialog(args);
case DIALOG_SUB_CATEGORIES: { case DIALOG_SUB_CATEGORIES: {
Builder builder = new AlertDialog.Builder(activity); Builder builder = new AlertDialog.Builder(activity);
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY); final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true); final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true);
final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]); final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]);
builder.setItems(subCats, new DialogInterface.OnClickListener() { builder.setItems(subCats, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
PoiType poiType = allTranslatedNames.get(subCats[which]); PoiType poiType = allTranslatedNames.get(subCats[which]);
typeText.setText(subCats[which]); typeText.setText(subCats[which]);
activity.removeDialog(DIALOG_SUB_CATEGORIES); activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
return builder.create();
}
case DIALOG_POI_TYPES: {
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
Builder builder = new AlertDialog.Builder(activity);
final List<PoiCategory> categories = poiTypes.getCategories(false);
String[] vals = new String[categories.size()];
for (int i = 0; i < vals.length; i++) {
vals[i] = categories.get(i).getTranslation();
}
builder.setItems(vals, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PoiCategory aType = categories.get(which);
if (aType != a.getType()) {
a.setType(aType);
a.setSubType(""); //$NON-NLS-1$
updateType(a);
} }
activity.removeDialog(DIALOG_POI_TYPES); });
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
activity.removeDialog(DIALOG_SUB_CATEGORIES);
}
});
return builder.create();
}
case DIALOG_POI_TYPES: {
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
Builder builder = new AlertDialog.Builder(activity);
final List<PoiCategory> categories = poiTypes.getCategories(false);
String[] vals = new String[categories.size()];
for (int i = 0; i < vals.length; i++) {
vals[i] = categories.get(i).getTranslation();
} }
}); builder.setItems(vals, new Dialog.OnClickListener() {
builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override
@Override public void onClick(DialogInterface dialog, int which) {
public void onCancel(DialogInterface dialog) { PoiCategory aType = categories.get(which);
activity.removeDialog(DIALOG_POI_TYPES); if (aType != a.getType()) {
} a.setType(aType);
}); a.setSubType(""); //$NON-NLS-1$
return builder.create(); updateType(a);
} }
case DIALOG_OPENING_HOURS: { activity.removeDialog(DIALOG_POI_TYPES);
return createOpenHoursDlg(); }
} });
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
activity.removeDialog(DIALOG_POI_TYPES);
}
});
return builder.create();
}
case DIALOG_OPENING_HOURS: {
return createOpenHoursDlg();
}
} }
return null; return null;
} }
@ -786,5 +785,4 @@ public class EditingPOIDialogProvider implements DialogProvider {
} }
} }
} }