From 56ec628f8ddf4669fb27fa794d7b946936580986 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Thu, 12 Nov 2015 11:48:12 +0200 Subject: [PATCH] Fixed bug with non clickable items in dialog (tags in edit poi). --- .../plus/osmedit/AdvancedEditPoiFragment.java | 104 +++++++++--------- 1 file changed, 49 insertions(+), 55 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index a5f58bc825..b22be6a991 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -1,24 +1,5 @@ package net.osmand.plus.osmedit; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import net.osmand.PlatformUtil; -import net.osmand.StringMatcher; -import net.osmand.osm.AbstractPoiType; -import net.osmand.osm.MapPoiTypes; -import net.osmand.osm.PoiCategory; -import net.osmand.osm.PoiFilter; -import net.osmand.osm.PoiType; -import net.osmand.osm.edit.OSMSettings; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; -import net.osmand.util.Algorithms; - -import org.apache.commons.logging.Log; - import android.app.Dialog; import android.content.DialogInterface; import android.graphics.Point; @@ -41,6 +22,25 @@ 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; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiFilter; +import net.osmand.osm.PoiType; +import net.osmand.osm.edit.OSMSettings; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.util.Algorithms; + +import org.apache.commons.logging.Log; + +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + public class AdvancedEditPoiFragment extends Fragment implements EditPoiDialogFragment.OnFragmentActivatedListener { private static final String TAG = "AdvancedEditPoiFragment"; @@ -218,25 +218,7 @@ public class AdvancedEditPoiFragment extends Fragment } } }); - - tagEditText.setAdapter(tagAdapter); - tagEditText.setThreshold(1); - tagEditText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setAdapter(tagAdapter, new Dialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - tagAdapter.getItem(which); - } - - }); - builder.create(); - builder.show(); - } - }); - + initAutocompleteTextView(tagEditText, tagAdapter); valueEditText.setText(vl); valueEditText.addTextChangedListener(new TextWatcher() { @@ -256,23 +238,7 @@ public class AdvancedEditPoiFragment extends Fragment } }); - valueEditText.setAdapter(valueAdapter); - valueEditText.setThreshold(1); - valueEditText.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setAdapter(valueAdapter, new Dialog.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - valueAdapter.getItem(which); - } - - }); - builder.create(); - builder.show(); - } - }); + initAutocompleteTextView(valueEditText, valueAdapter); linearLayout.addView(convertView); tagEditText.requestFocus(); @@ -293,6 +259,34 @@ public class AdvancedEditPoiFragment extends Fragment } } + private static void initAutocompleteTextView(final AutoCompleteTextView textView, + final ArrayAdapter adapter) { + textView.setAdapter(adapter); + textView.setThreshold(1); + textView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); + builder.setAdapter(adapter, new Dialog.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + textView.setText(adapter.getItem(which)); + } + + }); + builder.create().show(); + } + }); + textView.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + adapter.getFilter().filter(textView.getText()); + } + } + }); + } + private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set stringSet, Set values) { if (abstractPoiType instanceof PoiType) {