Tag autocomplete reimplemented

This commit is contained in:
GaidamakUA 2015-08-29 16:48:45 +03:00
parent f3f84da3b8
commit 4a7c7f9c0e
4 changed files with 69 additions and 25 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" > android:layout_height="fill_parent" >
@ -201,7 +202,9 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:stretchColumns="1" android:stretchColumns="1"
android:visibility="gone" > android:visibility="gone"
tools:layout_height="25dp"
tools:visibility="visible">
</TableLayout> </TableLayout>
<LinearLayout <LinearLayout

View file

@ -14,7 +14,7 @@
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_weight="1"> android:layout_weight="1">
<EditText <AutoCompleteTextView
android:id="@+id/tagEditText" android:id="@+id/tagEditText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View file

@ -1,15 +1,21 @@
package net.osmand.plus.osmedit; package net.osmand.plus.osmedit;
import android.app.Dialog;
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.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageButton; import android.widget.ImageButton;
@ -29,6 +35,8 @@ import org.apache.commons.logging.Log;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class AdvancedDataFragment extends Fragment { public class AdvancedDataFragment extends Fragment {
private static final String TAG = "AdvancedDataFragment"; private static final String TAG = "AdvancedDataFragment";
@ -99,6 +107,14 @@ public class AdvancedDataFragment extends Fragment {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
private EditPoiFragment getEditPoiFragment() {
return (EditPoiFragment) getParentFragment();
}
private EditPoiData getData() {
return getEditPoiFragment().getEditPoiData();
}
public class TagAdapterLinearLayoutHack { public class TagAdapterLinearLayoutHack {
private final LinearLayout linearLayout; private final LinearLayout linearLayout;
private final EditPoiData editPoiData; private final EditPoiData editPoiData;
@ -131,7 +147,6 @@ public class AdvancedDataFragment extends Fragment {
public void updateViews() { public void updateViews() {
linearLayout.removeAllViews(); linearLayout.removeAllViews();
Iterator<Tag> iterator = editPoiData.tags.iterator();
for (Tag tag : editPoiData.tags) { for (Tag tag : editPoiData.tags) {
if (tag.tag.equals(OSMSettings.OSMTagKey.NAME.getValue())) { if (tag.tag.equals(OSMSettings.OSMTagKey.NAME.getValue())) {
nameTextView.setText(tag.value); nameTextView.setText(tag.value);
@ -155,7 +170,8 @@ public class AdvancedDataFragment extends Fragment {
private View getView(final Tag tag) { private View getView(final Tag tag) {
final View convertView = LayoutInflater.from(linearLayout.getContext()) final View convertView = LayoutInflater.from(linearLayout.getContext())
.inflate(R.layout.poi_tag_list_item, null, false); .inflate(R.layout.poi_tag_list_item, null, false);
final EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText); final AutoCompleteTextView tagEditText =
(AutoCompleteTextView) convertView.findViewById(R.id.tagEditText);
tagEditText.setText(tag.tag); tagEditText.setText(tag.tag);
final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText); final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
ImageButton deleteItemImageButton = ImageButton deleteItemImageButton =
@ -193,6 +209,35 @@ public class AdvancedDataFragment extends Fragment {
editPoiData.notifyDatasetChanged(mTagsChangedListener); editPoiData.notifyDatasetChanged(mTagsChangedListener);
} }
}); });
final Set<String> tagKeys = new TreeSet<String>();
for (OSMSettings.OSMTagKey t : OSMSettings.OSMTagKey.values()) {
if ((t != OSMSettings.OSMTagKey.NAME) && (t != OSMSettings.OSMTagKey.OPENING_HOURS) && (t != OSMSettings.OSMTagKey.PHONE)
&& (t != OSMSettings.OSMTagKey.WEBSITE)) {
tagKeys.add(t.getValue());
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(linearLayout.getContext(),
R.layout.list_textview, tagKeys.toArray());
tagEditText.setAdapter(adapter);
tagEditText.setThreshold(1);
tagEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: 8/29/15 Rewrite as dialog fragment
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
builder.setItems(tags, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
tagEditText.setText(tags[which]);
}
});
builder.create();
builder.show();
}
});
valueEditText.addTextChangedListener(new TextWatcher() { valueEditText.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@ -214,12 +259,4 @@ public class AdvancedDataFragment extends Fragment {
return convertView; return convertView;
} }
} }
private EditPoiFragment getEditPoiFragment() {
return (EditPoiFragment) getParentFragment();
}
private EditPoiData getData() {
return getEditPoiFragment().getEditPoiData();
}
} }

View file

@ -42,11 +42,13 @@ import java.util.List;
public class OsmEditingPlugin extends OsmandPlugin { public class OsmEditingPlugin extends OsmandPlugin {
private static final Log LOG = PlatformUtil.getLog(OsmEditingPlugin.class);
private static final String ID = "osm.editing"; private static final String ID = "osm.editing";
private OsmandSettings settings; private OsmandSettings settings;
private OsmandApplication app; private OsmandApplication app;
OpenstreetmapsDbHelper dbpoi; OpenstreetmapsDbHelper dbpoi;
OsmBugsDbHelper dbbug; OsmBugsDbHelper dbbug;
private EditingPOIDialogProvider poiActions;
@Override @Override
public String getId() { public String getId() {
@ -136,12 +138,12 @@ public class OsmEditingPlugin extends OsmandPlugin {
return SettingsOsmEditingActivity.class; return SettingsOsmEditingActivity.class;
} }
// public EditingPOIDialogProvider getPoiActions(MapActivity activity) { public EditingPOIDialogProvider getPoiActions(MapActivity activity) {
// if (poiActions == null) { if (poiActions == null) {
// poiActions = new EditingPOIDialogProvider(activity, this); poiActions = new EditingPOIDialogProvider(activity, this);
// } }
// return poiActions; return poiActions;
// } }
@Override @Override
public void registerMapContextMenuActions(final MapActivity mapActivity, public void registerMapContextMenuActions(final MapActivity mapActivity,
@ -152,6 +154,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
OnContextMenuClick listener = new OnContextMenuClick() { OnContextMenuClick listener = new OnContextMenuClick() {
@Override @Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
LOG.debug("onContextMenuClick()");
if (resId == R.string.context_menu_item_create_poi) { if (resId == R.string.context_menu_item_create_poi) {
//getPoiActions(mapActivity).showCreateDialog(latitude, longitude); //getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
EditPoiFragment editPoiFragment = EditPoiFragment editPoiFragment =
@ -167,14 +170,15 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
osmBugsLayer.openBug(latitude, longitude); osmBugsLayer.openBug(latitude, longitude);
} else if (resId == R.string.poi_context_menu_delete) { } else if (resId == R.string.poi_context_menu_delete) {
new EditPoiFragment.ShowDeleteDialogAsyncTask(mapActivity) LOG.debug("delete poi");
.execute((Amenity) selectedObj); // new EditPoiFragment.ShowDeleteDialogAsyncTask(mapActivity)
// .execute((Amenity) selectedObj);
// TODO implement delete // TODO implement delete
// getPoiActions(mapActivity).showDeleteDialog((Amenity) selectedObj); getPoiActions(mapActivity).showDeleteDialog((Amenity) selectedObj);
}//} else if (resId == R.string.poi_context_menu_modify) { } else if (resId == R.string.poi_context_menu_modify) {
// TODO implement edit // TODO implement edit
// getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj); getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj);
// } }
return true; return true;
} }
}; };