From 9752081bc8f78b57c0fc4d255d3d76bf869ecf78 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 9 Nov 2015 11:36:10 +0200 Subject: [PATCH 1/3] Android 4 crash fix --- .../net/osmand/plus/osmedit/EditPoiDialogFragment.java | 2 -- .../plus/osmedit/dialogs/DeletePoiDialogFragment.java | 9 +++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 5ec24ac042..6fcddc5b54 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -254,7 +254,6 @@ public class EditPoiDialogFragment extends DialogFragment { @Override public void onClick(View v) { save(); - } }); Button cancelButton = (Button) view.findViewById(R.id.cancelButton); @@ -570,7 +569,6 @@ public class EditPoiDialogFragment extends DialogFragment { } } - // TODO: 8/28/15 Move to helper public static class ShowDeleteDialogAsyncTask extends AsyncTask { private final OpenstreetmapUtil openstreetmapUtil; private final AppCompatActivity activity; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java index f4dee8ebdf..66bfa44ae2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java @@ -22,12 +22,17 @@ import net.osmand.plus.osmedit.OsmPoint; public class DeletePoiDialogFragment extends DialogFragment { private static final String KEY_AMENITY_NODE = "amenity_node"; + Activity activity; + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + this.activity = activity; + } @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - final Activity activity = getActivity(); - OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); final OpenstreetmapUtil mOpenstreetmapUtil; mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); From e0ec618e6957541a6fdda1b9bc1747eaa0594aae Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 9 Nov 2015 13:13:50 +0200 Subject: [PATCH 2/3] Delete dialog reverted to alert dialog --- .../plus/osmedit/EditPoiDialogFragment.java | 57 ++++++++++++-- .../dialogs/DeletePoiDialogFragment.java | 74 ------------------- 2 files changed, 51 insertions(+), 80 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 2e998be40e..0e9fe69797 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -38,8 +38,10 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageButton; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -56,7 +58,6 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.osmedit.dialogs.DeletePoiDialogFragment; import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment; import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment; import net.osmand.util.Algorithms; @@ -247,8 +248,8 @@ public class EditPoiDialogFragment extends DialogFragment { poiTypeEditText.setText(editPoiData.amenity.getSubType()); Button saveButton = (Button) view.findViewById(R.id.saveButton); - saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil? R.string.shared_string_upload : - R.string.shared_string_save); + saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil + ? R.string.shared_string_upload : R.string.shared_string_save); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -588,14 +589,58 @@ public class EditPoiDialogFragment extends DialogFragment { return openstreetmapUtil.loadNode(params[0]); } - protected void onPostExecute(Node n) { + protected void onPostExecute(final Node n) { if (n == null) { AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_poi_not_found), Toast.LENGTH_LONG).show(); return; } // FIXME give back alert dialog and use openstreetmapUtil field! - DeletePoiDialogFragment.createInstance(n).show(activity.getSupportFragmentManager(), - "DeletePoiDialogFragment"); + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(R.string.poi_remove_title); + final EditText comment; + final CheckBox closeChangesetCheckBox; + final boolean isLocalEdit = openstreetmapUtil instanceof OpenstreetmapLocalUtil; + if (isLocalEdit) { + closeChangesetCheckBox = null; + comment = null; + } else { + LinearLayout ll = new LinearLayout(activity); + ll.setPadding(16, 2, 16, 0); + ll.setOrientation(LinearLayout.VERTICAL); + closeChangesetCheckBox = new CheckBox(activity); + closeChangesetCheckBox.setText(R.string.close_changeset); + ll.addView(closeChangesetCheckBox); + comment = new EditText(activity); + comment.setText(R.string.poi_remove_title); + ll.addView(comment); + builder.setView(ll); + } + builder.setNegativeButton(R.string.shared_string_cancel, null); + builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + String c = comment == null ? null : comment.getText().toString(); + boolean closeChangeSet = closeChangesetCheckBox != null + && closeChangesetCheckBox.isSelected(); + commitNode(OsmPoint.Action.DELETE, n, openstreetmapUtil.getEntityInfo(), c, + closeChangeSet, new Runnable() { + @Override + public void run() { + if (isLocalEdit) { + AccessibleToast.makeText( + activity, R.string.osm_changes_added_to_local_edits, + Toast.LENGTH_LONG).show(); + } else { + AccessibleToast.makeText(activity, R.string.poi_remove_success, Toast.LENGTH_LONG).show(); + } + if (activity instanceof MapActivity) { + ((MapActivity) activity).getMapView().refreshMap(true); + } + } + }, activity, openstreetmapUtil); + } + }); + builder.create().show(); } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java deleted file mode 100644 index 66bfa44ae2..0000000000 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DeletePoiDialogFragment.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.osmand.plus.osmedit.dialogs; - -import android.app.Activity; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; -import android.support.v7.app.AlertDialog; -import android.widget.Toast; - -import net.osmand.access.AccessibleToast; -import net.osmand.osm.edit.Node; -import net.osmand.plus.OsmandPlugin; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.osmedit.EditPoiDialogFragment; -import net.osmand.plus.osmedit.OpenstreetmapLocalUtil; -import net.osmand.plus.osmedit.OpenstreetmapUtil; -import net.osmand.plus.osmedit.OsmEditingPlugin; -import net.osmand.plus.osmedit.OsmPoint; - -public class DeletePoiDialogFragment extends DialogFragment { - private static final String KEY_AMENITY_NODE = "amenity_node"; - Activity activity; - - @Override - public void onAttach(Activity activity) { - super.onAttach(activity); - this.activity = activity; - } - - @NonNull - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); - final OpenstreetmapUtil mOpenstreetmapUtil; - mOpenstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); - - final Bundle args = getArguments(); - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - builder.setTitle(R.string.poi_remove_title); - builder.setNegativeButton(R.string.shared_string_cancel, null); - builder.setPositiveButton(R.string.shared_string_delete, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Node node = (Node) args.getSerializable(KEY_AMENITY_NODE); - EditPoiDialogFragment.commitNode(OsmPoint.Action.DELETE, node, - mOpenstreetmapUtil.getEntityInfo(), null, false, - new Runnable() { - @Override - public void run() { - AccessibleToast.makeText(activity, - getString(R.string.poi_deleted_localy), - Toast.LENGTH_LONG).show(); - if (activity instanceof MapActivity) { - ((MapActivity) activity).getMapView().refreshMap(true); - } - } - }, - getActivity(), mOpenstreetmapUtil); - } - }); - return builder.create(); - } - - public static DeletePoiDialogFragment createInstance(Node amenityNode) { - DeletePoiDialogFragment fragment = new DeletePoiDialogFragment(); - Bundle bundle = new Bundle(); - bundle.putSerializable(KEY_AMENITY_NODE, amenityNode); - fragment.setArguments(bundle); - return fragment; - } -} From 126a951602e10d13d6aca7f300bb4f6dcca48bb2 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 9 Nov 2015 13:35:50 +0200 Subject: [PATCH 3/3] After add tag cursor now moving to newly created text field --- .../osmand/plus/osmedit/AdvancedEditPoiFragment.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index 1e742be7cf..eafefe8ad8 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -21,6 +21,7 @@ import android.widget.Button; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.TextView; + import net.osmand.PlatformUtil; import net.osmand.StringMatcher; import net.osmand.osm.AbstractPoiType; @@ -176,12 +177,6 @@ public class AdvancedEditPoiFragment extends Fragment } public void addTagView(String tg, String vl) { - View view = getView(tg, vl); - LOG.debug("tg=" + tg + "; view=" + view); - linearLayout.addView(view); - } - - private View getView(String tg, String vl) { View convertView = LayoutInflater.from(linearLayout.getContext()) .inflate(R.layout.poi_tag_list_item, null, false); final AutoCompleteTextView tagEditText = @@ -277,7 +272,8 @@ public class AdvancedEditPoiFragment extends Fragment } }); - return convertView; + linearLayout.addView(convertView); + tagEditText.requestFocus(); } public void setTagData(String[] tags) {