add poi action

This commit is contained in:
Korusn Oleksandr 2017-01-04 14:56:31 +02:00
parent 3951b2e4b8
commit 68250e6ed7
4 changed files with 279 additions and 46 deletions

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="?attr/new_app_theme">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/editTagsList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:orientation="vertical"
android:saveEnabled="false"/>
<net.osmand.plus.widgets.ButtonEx
android:id="@+id/addTagButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginTop="16dp"
android:background="@color/osmand_orange"
android:textColor="@color/color_white"
android:text="@string/add_tag"
android:textSize="@dimen/default_sub_text_size"
osmand:typeface="@string/font_roboto_medium"/>
</LinearLayout>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -267,7 +267,7 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment
}); });
} }
private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet, public static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet,
Set<String> values) { Set<String> values) {
if (abstractPoiType instanceof PoiType) { if (abstractPoiType instanceof PoiType) {
PoiType poiType = (PoiType) abstractPoiType; PoiType poiType = (PoiType) abstractPoiType;

View file

@ -1,33 +1,5 @@
package net.osmand.plus.osmedit; package net.osmand.plus.osmedit;
import java.io.Serializable;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
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.base.BaseOsmAndDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
@ -74,6 +46,35 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
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.base.BaseOsmAndDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
public static final String TAG = "EditPoiDialogFragment"; public static final String TAG = "EditPoiDialogFragment";
private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class); private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class);
@ -82,7 +83,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
private static final String TAGS_LIST = "tags_list"; private static final String TAGS_LIST = "tags_list";
private static final String IS_ADDING_POI = "is_adding_poi"; private static final String IS_ADDING_POI = "is_adding_poi";
private static final HashSet<String> BASIC_TAGS = new HashSet<String>() { public static final HashSet<String> BASIC_TAGS = new HashSet<String>() {
{ {
add(OSMSettings.OSMTagKey.NAME.getValue()); add(OSMSettings.OSMTagKey.NAME.getValue());
add(OSMSettings.OSMTagKey.ADDR_STREET.getValue()); add(OSMSettings.OSMTagKey.ADDR_STREET.getValue());
@ -114,6 +115,15 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
Node node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE); Node node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
editPoiData = new EditPoiData(node, getMyApplication()); editPoiData = new EditPoiData(node, getMyApplication());
if (getArguments().getSerializable(TAGS_LIST) != null && view == null) {
for (Map.Entry<String, String> tag : ((Map<String, String>) getArguments().getSerializable(TAGS_LIST)).entrySet())
editPoiData.putTag(tag.getKey(), tag.getValue());
}
// if (getArguments().getSerializable(TAGS_LIST) != null && editPoiData.getTagValues().isEmpty()) {
// //noinspection unchecked
// editPoiData.updateTags((Map<String, String>) getArguments().getSerializable(TAGS_LIST));
// }
} }
@Override @Override
@ -574,6 +584,16 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
return editPoiDialogFragment; return editPoiDialogFragment;
} }
public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi, Map<String, String> tagList) {
EditPoiDialogFragment editPoiDialogFragment = new EditPoiDialogFragment();
Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY_NODE, node);
args.putBoolean(IS_ADDING_POI, isAddingPoi);
args.putSerializable(TAGS_LIST, (Serializable) Collections.unmodifiableMap(tagList));
editPoiDialogFragment.setArguments(args);
return editPoiDialogFragment;
}
public static void showEditInstance(final Amenity amenity, public static void showEditInstance(final Amenity amenity,
final AppCompatActivity activity) { final AppCompatActivity activity) {
final OsmandSettings settings = ((OsmandApplication) activity.getApplication()) final OsmandSettings settings = ((OsmandApplication) activity.getApplication())

View file

@ -4,24 +4,24 @@ package net.osmand.plus.quickaction;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; 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.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -32,7 +32,11 @@ import com.google.gson.reflect.TypeToken;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.PoiFilter; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
@ -41,12 +45,12 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.EditPoiData;
import net.osmand.plus.osmedit.EditPoiDialogFragment; import net.osmand.plus.osmedit.EditPoiDialogFragment;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
@ -57,18 +61,18 @@ import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.widgets.AutoCompleteTextViewEx; import net.osmand.plus.widgets.AutoCompleteTextViewEx;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
import net.osmand.search.core.CustomSearchPoiFilter;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Map;
import java.util.Map.Entry;
import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static net.osmand.plus.osmedit.AdvancedEditPoiFragment.addPoiToStringSet;
public class QuickActionFactory { public class QuickActionFactory {
@ -1201,6 +1205,7 @@ public class QuickActionFactory {
public static class AddPOIAction extends QuickAction { public static class AddPOIAction extends QuickAction {
public static final int TYPE = 13; public static final int TYPE = 13;
public static final String KEY_TAG = "key_tag";
protected AddPOIAction() { protected AddPOIAction() {
id = System.currentTimeMillis(); id = System.currentTimeMillis();
@ -1223,8 +1228,9 @@ public class QuickActionFactory {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null) { if (plugin != null) {
EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment editPoiDialogFragment =
EditPoiDialogFragment.createAddPoiInstance(latLon.getLatitude(), latLon.getLongitude(), // EditPoiDialogFragment.createAddPoiInstance(latLon.getLatitude(), latLon.getLongitude(),
activity.getMyApplication()); // activity.getMyApplication());
EditPoiDialogFragment.createInstance(new Node(latLon.getLatitude(), latLon.getLongitude(), -1), true, getTagsFromParams());
editPoiDialogFragment.show(activity.getSupportFragmentManager(), editPoiDialogFragment.show(activity.getSupportFragmentManager(),
EditPoiDialogFragment.TAG); EditPoiDialogFragment.TAG);
} }
@ -1232,15 +1238,182 @@ public class QuickActionFactory {
@Override @Override
public void drawUI(ViewGroup parent, MapActivity activity) { public void drawUI(ViewGroup parent, MapActivity activity) {
final View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.quick_action_add_poi_layout, parent, false);
View view = LayoutInflater.from(parent.getContext()) OsmandApplication application = activity.getMyApplication();
.inflate(R.layout.quick_action_with_text, parent, false); Drawable deleteDrawable = application.getIconsCache().getPaintedIcon(R.drawable.ic_action_remove_dark,
activity.getResources().getColor(R.color.dash_search_icon_dark));
((TextView) view.findViewById(R.id.text)).setText( LinearLayout editTagsLineaLayout =
R.string.quick_action_add_poi_discr); (LinearLayout) view.findViewById(R.id.editTagsList);
final MapPoiTypes mapPoiTypes = application.getPoiTypes();
final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable);
// It is possible to not restart initialization every time, and probably move initialization to appInit
Map<String, PoiType> translatedTypes = mapPoiTypes.getAllTranslatedNames(true);
HashSet<String> tagKeys = new HashSet<>();
HashSet<String> valueKeys = new HashSet<>();
for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
}
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
// tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS); //TODO: ask for basic
mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
addTagButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAdapter.addTagView("", "");
}
});
mAdapter.updateViews();
parent.addView(view); parent.addView(view);
} }
private class TagAdapterLinearLayoutHack {
private final LinearLayout linearLayout;
private final Map<String, String> tagsData;
private final ArrayAdapter<String> tagAdapter;
private final ArrayAdapter<String> valueAdapter;
private final Drawable deleteDrawable;
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
Map<String, String> tagsData,
Drawable deleteDrawable) {
this.linearLayout = linearLayout;
this.tagsData = tagsData;
this.deleteDrawable = deleteDrawable;
tagAdapter = new ArrayAdapter<>(linearLayout.getContext(), R.layout.list_textview);
valueAdapter = new ArrayAdapter<>(linearLayout.getContext(), R.layout.list_textview);
}
public void updateViews() {
linearLayout.removeAllViews();
List<Entry<String, String>> entries = new ArrayList<>(tagsData.entrySet());
for (Entry<String, String> tag : entries) {
if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)
|| tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue()))
continue;
addTagView(tag.getKey(), tag.getValue());
}
}
public void addTagView(String tg, String vl) {
View convertView = LayoutInflater.from(linearLayout.getContext())
.inflate(R.layout.poi_tag_list_item, null, false);
final AutoCompleteTextView tagEditText =
(AutoCompleteTextView) convertView.findViewById(R.id.tagEditText);
ImageButton deleteItemImageButton =
(ImageButton) convertView.findViewById(R.id.deleteItemImageButton);
deleteItemImageButton.setImageDrawable(deleteDrawable);
final String[] previousTag = new String[]{tg};
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linearLayout.removeView((View) v.getParent());
tagsData.remove(tagEditText.getText().toString());
setTagsIntoParams(tagsData);
}
});
final AutoCompleteTextView valueEditText =
(AutoCompleteTextView) convertView.findViewById(R.id.valueEditText);
tagEditText.setText(tg);
tagEditText.setAdapter(tagAdapter);
tagEditText.setThreshold(1);
tagEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
String s = tagEditText.getText().toString();
tagsData.remove(previousTag[0]);
tagsData.put(s.toString(), valueEditText.getText().toString());
previousTag[0] = s.toString();
setTagsIntoParams(tagsData);
} else {
tagAdapter.getFilter().filter(tagEditText.getText());
}
}
});
valueEditText.setText(vl);
valueEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
tagsData.put(tagEditText.getText().toString(), s.toString());
setTagsIntoParams(tagsData);
}
});
initAutocompleteTextView(valueEditText, valueAdapter);
linearLayout.addView(convertView);
tagEditText.requestFocus();
}
public void setTagData(String[] tags) {
tagAdapter.clear();
for (String s : tags) {
tagAdapter.add(s);
}
tagAdapter.sort(String.CASE_INSENSITIVE_ORDER);
tagAdapter.notifyDataSetChanged();
}
public void setValueData(String[] values) {
valueAdapter.clear();
for (String s : values) {
valueAdapter.add(s);
}
valueAdapter.sort(String.CASE_INSENSITIVE_ORDER);
valueAdapter.notifyDataSetChanged();
}
}
private static void initAutocompleteTextView(final AutoCompleteTextView textView,
final ArrayAdapter<String> adapter) {
textView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
adapter.getFilter().filter(textView.getText());
}
}
});
}
@Override
public boolean fillParams(View root, MapActivity activity) {
return !getParams().isEmpty() && (getParams().get(KEY_TAG) != null || !getTagsFromParams().isEmpty());
}
private Map<String, String> getTagsFromParams() {
Map<String, String> quickActions = null;
if (getParams().get(KEY_TAG) != null) {
String json = getParams().get(KEY_TAG);
Type type = new TypeToken<LinkedHashMap<String, String>>() {
}.getType();
quickActions = new Gson().fromJson(json, type);
}
return quickActions != null ? quickActions : new LinkedHashMap<String, String>();
}
private void setTagsIntoParams(Map<String, String> tags) {
getParams().put(KEY_TAG, new Gson().toJson(tags));
}
} }
public static class MapStyleAction extends QuickAction { public static class MapStyleAction extends QuickAction {