From 44f2e3b6ff46114d4ba7bb7db2eb491456d68533 Mon Sep 17 00:00:00 2001 From: Korusn Oleksandr Date: Fri, 6 Jan 2017 14:04:54 +0200 Subject: [PATCH] add poi, poi type (no skip dialog yet) --- .../res/drawable/bg_orange_rounded_coners.xml | 24 ++ .../layout/quick_action_add_poi_layout.xml | 143 +++++++++++- OsmAnd/res/values/strings.xml | 1 + .../src/net/osmand/plus/OsmandSettings.java | 4 +- .../plus/osmedit/EditPoiDialogFragment.java | 18 +- .../osmand/plus/osmedit/OsmEditingPlugin.java | 7 + .../dialogs/PoiSubTypeDialogFragment.java | 27 ++- .../dialogs/PoiTypeDialogFragment.java | 25 ++- .../quickaction/AddQuickActionDialog.java | 3 +- .../plus/quickaction/QuickActionFactory.java | 211 +++++++++++++++++- 10 files changed, 419 insertions(+), 44 deletions(-) create mode 100644 OsmAnd/res/drawable/bg_orange_rounded_coners.xml diff --git a/OsmAnd/res/drawable/bg_orange_rounded_coners.xml b/OsmAnd/res/drawable/bg_orange_rounded_coners.xml new file mode 100644 index 0000000000..abee6e3b11 --- /dev/null +++ b/OsmAnd/res/drawable/bg_orange_rounded_coners.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/quick_action_add_poi_layout.xml b/OsmAnd/res/layout/quick_action_add_poi_layout.xml index 071a3e2101..5a5907ea6e 100644 --- a/OsmAnd/res/layout/quick_action_add_poi_layout.xml +++ b/OsmAnd/res/layout/quick_action_add_poi_layout.xml @@ -4,23 +4,134 @@ xmlns:osmand="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:tools="http://schemas.android.com/tools" android:theme="?attr/new_app_theme"> - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -28,13 +139,29 @@ android:id="@+id/addTagButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginLeft="12dp" + android:layout_marginLeft="16dp" android:layout_marginTop="16dp" - android:background="@color/osmand_orange" - android:textColor="@color/color_white" + android:background="@drawable/bg_orange_rounded_coners" + android:paddingLeft="16dp" + android:paddingRight="16dp" android:text="@string/add_tag" + android:textColor="@color/color_white" android:textSize="@dimen/default_sub_text_size" osmand:typeface="@string/font_roboto_medium"/> + + + + + + + + + + + + + + - + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index e11db20856..4fed45d540 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2503,6 +2503,7 @@ If you need help with OsmAnd application, please contact our support team: suppo Tap on action will disable or enable voice during navigation. Tap on action will add Parking place to the specified location. Show favorite dialog + Show add POI dialog Show GPX waypoint dialog " is saved to " Place diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 81a41b9302..c4d47659c8 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -2454,9 +2454,9 @@ public class OsmandSettings { public static final String QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN = "quick_fab_margin_x_landscape_margin"; public static final String QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN = "quick_fab_margin_y_landscape_margin"; - public final CommonPreference QUICK_ACTION = new StringPreference("quick_action_new", "").makeProfile(); + public final CommonPreference QUICK_ACTION = new StringPreference("quick_action_new", "").makeGlobal(); - public final CommonPreference QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile(); + public final CommonPreference QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeGlobal(); public boolean setPortraitFabMargin(int x, int y) { return settingsAPI.edit(globalPreferences).putInt(QUICK_FAB_MARGIN_X_PORTRAIT_MARGIN, x) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index c18de3c766..2ad32624c4 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -127,8 +127,6 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { @SuppressWarnings("unchecked") Map mp = (Map) savedInstanceState.getSerializable(TAGS_LIST); editPoiData.updateTags(mp); - } else if (getArguments().getSerializable(TAGS_LIST) != null){ - editPoiData.updateTags((Map) getArguments().getSerializable(TAGS_LIST)); } boolean isAddingPoi = getArguments().getBoolean(IS_ADDING_POI); @@ -222,7 +220,13 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { poiTypeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - DialogFragment fragment = PoiTypeDialogFragment.createInstance(); + PoiTypeDialogFragment fragment = PoiTypeDialogFragment.createInstance(); + fragment.setOnItemSelectListener(new PoiTypeDialogFragment.OnItemSelectListener() { + @Override + public void select(PoiCategory poiCategory) { + setPoiCategory(poiCategory); + } + }); fragment.show(getChildFragmentManager(), "PoiTypeDialogFragment"); } }); @@ -282,8 +286,14 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() - editText.getPaddingRight())) { if (editPoiData.getPoiCategory() != null) { - DialogFragment dialogFragment = + PoiSubTypeDialogFragment dialogFragment = PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory()); + dialogFragment.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() { + @Override + public void select(String category) { + setSubCategory(category); + } + }); dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment"); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 083332c01c..b28c69b45f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -232,6 +232,13 @@ public class OsmEditingPlugin extends OsmandPlugin { osmBugsLayer.openBug(latitude, longitude, ""); } + public void openOsmNote(MapActivity mapActivity, double latitude, double longitude, String message) { + if (osmBugsLayer == null) { + registerLayers(mapActivity); + } + osmBugsLayer.openBug(latitude, longitude, message); + } + @Override public void addMyPlacesTab(FavoritesActivity favoritesActivity, List mTabs, Intent intent) { if (getDBPOI().getOpenstreetmapPoints().size() > 0 || getDBBug().getOsmbugsPoints().size() > 0) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java index f02248f683..9f72bdbe91 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiSubTypeDialogFragment.java @@ -1,13 +1,5 @@ package net.osmand.plus.osmedit.dialogs; -import java.util.Set; -import java.util.TreeSet; - -import net.osmand.osm.MapPoiTypes; -import net.osmand.osm.PoiCategory; -import net.osmand.osm.PoiType; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.osmedit.EditPoiDialogFragment; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; @@ -15,8 +7,17 @@ import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiType; +import net.osmand.plus.OsmandApplication; + +import java.util.Set; +import java.util.TreeSet; + public class PoiSubTypeDialogFragment extends DialogFragment { private static final String KEY_POI_CATEGORY = "amenity"; + private OnItemSelectListener onItemSelectListener; @NonNull @Override @@ -38,7 +39,7 @@ public class PoiSubTypeDialogFragment extends DialogFragment { builder.setItems(subCats, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - ((EditPoiDialogFragment) getParentFragment()).setSubCategory(subCats[which]); + onItemSelectListener.select(subCats[which]); dismiss(); } }); @@ -60,4 +61,12 @@ public class PoiSubTypeDialogFragment extends DialogFragment { fragment.setArguments(args); return fragment; } + + public void setOnItemSelectListener(OnItemSelectListener onItemSelectListener) { + this.onItemSelectListener = onItemSelectListener; + } + + public interface OnItemSelectListener { + void select(String category); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java index 808ce6acf4..d4c01865f6 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/PoiTypeDialogFragment.java @@ -1,12 +1,5 @@ package net.osmand.plus.osmedit.dialogs; -import java.util.ArrayList; -import java.util.List; - -import net.osmand.osm.MapPoiTypes; -import net.osmand.osm.PoiCategory; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.osmedit.EditPoiDialogFragment; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; @@ -14,7 +7,15 @@ import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; +import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; +import net.osmand.plus.OsmandApplication; + +import java.util.ArrayList; +import java.util.List; + public class PoiTypeDialogFragment extends DialogFragment { + private OnItemSelectListener onItemSelectListener; @NonNull @Override @@ -33,7 +34,7 @@ public class PoiTypeDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { PoiCategory aType = categories.get(which); - ((EditPoiDialogFragment) getParentFragment()).setPoiCategory(aType); + onItemSelectListener.select(aType); dismiss(); } }); @@ -46,4 +47,12 @@ public class PoiTypeDialogFragment extends DialogFragment { poiTypeDialogFragment.setArguments(args); return poiTypeDialogFragment; } + + public void setOnItemSelectListener(OnItemSelectListener onItemSelectListener) { + this.onItemSelectListener = onItemSelectListener; + } + + public interface OnItemSelectListener { + void select(PoiCategory poiCategory); + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java index 3bfd15ecd4..fba324b203 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java @@ -5,7 +5,6 @@ import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.DialogFragment; - import android.support.v7.view.ContextThemeWrapper; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -155,7 +154,7 @@ public class AddQuickActionDialog extends DialogFragment { public void onClick(View view) { CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.type); - dialog.show(getFragmentManager(), AddQuickActionDialog.TAG); + dialog.show(getFragmentManager(), CreateEditActionDialog.TAG); dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index 45cd15d38a..43861875fd 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -5,7 +5,12 @@ import android.app.Dialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Build; +import android.support.design.widget.TextInputLayout; import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; import android.support.v4.util.Pair; @@ -17,13 +22,16 @@ import android.support.v7.widget.helper.ItemTouchHelper; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; @@ -38,9 +46,9 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; +import net.osmand.osm.PoiCategory; 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.ContextMenuItem; import net.osmand.plus.FavouritesDbHelper; @@ -55,9 +63,9 @@ import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; -import net.osmand.plus.osmedit.EditPoiData; import net.osmand.plus.osmedit.EditPoiDialogFragment; import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; @@ -67,11 +75,13 @@ import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.widgets.AutoCompleteTextViewEx; import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.Algorithms; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -80,6 +90,7 @@ import java.util.Map.Entry; import java.util.Set; import static net.osmand.plus.osmedit.AdvancedEditPoiFragment.addPoiToStringSet; +import static net.osmand.plus.osmedit.EditPoiData.POI_TYPE_TAG; public class QuickActionFactory { @@ -1451,6 +1462,7 @@ public class QuickActionFactory { public static class AddPOIAction extends QuickAction { public static final int TYPE = 13; public static final String KEY_TAG = "key_tag"; + public static final String KEY_DIALOG = "dialog"; protected AddPOIAction() { super(TYPE); @@ -1469,17 +1481,17 @@ public class QuickActionFactory { OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); if (plugin != null) { + Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1); + node.replaceTags(getTagsFromParams()); EditPoiDialogFragment editPoiDialogFragment = -// EditPoiDialogFragment.createAddPoiInstance(latLon.getLatitude(), latLon.getLongitude(), -// activity.getMyApplication()); - EditPoiDialogFragment.createInstance(new Node(latLon.getLatitude(), latLon.getLongitude(), -1), true, getTagsFromParams()); + EditPoiDialogFragment.createInstance(node, true, getTagsFromParams()); editPoiDialogFragment.show(activity.getSupportFragmentManager(), EditPoiDialogFragment.TAG); } } @Override - public void drawUI(ViewGroup parent, MapActivity activity) { + public void drawUI(final ViewGroup parent, final MapActivity activity) { final View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.quick_action_add_poi_layout, parent, false); @@ -1490,16 +1502,17 @@ public class QuickActionFactory { LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList); - final MapPoiTypes mapPoiTypes = application.getPoiTypes(); + final MapPoiTypes poiTypes = application.getPoiTypes(); + final Map allTranslatedNames = poiTypes.getAllTranslatedNames(true); final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable); // It is possible to not restart initialization every time, and probably move initialization to appInit - Map translatedTypes = mapPoiTypes.getAllTranslatedNames(true); + Map translatedTypes = poiTypes.getAllTranslatedNames(true); HashSet tagKeys = new HashSet<>(); HashSet valueKeys = new HashSet<>(); for (AbstractPoiType abstractPoiType : translatedTypes.values()) { addPoiToStringSet(abstractPoiType, tagKeys, valueKeys); } - addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys); + addPoiToStringSet(poiTypes.getOtherMapCategory(), tagKeys, valueKeys); tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS); mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()])); mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()])); @@ -1513,9 +1526,179 @@ public class QuickActionFactory { mAdapter.updateViews(); + final TextInputLayout poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout); + final AutoCompleteTextView poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText); + final SwitchCompat showDialog = (SwitchCompat) view.findViewById(R.id.saveButton); + showDialog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + getParams().put(KEY_DIALOG, Boolean.toString(isChecked)); + } + }); + showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG))); + + String text = getTagsFromParams().get(POI_TYPE_TAG); + poiTypeEditText.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) { + String tp = s.toString(); + putTagIntoParams(POI_TYPE_TAG, tp); + PoiCategory category = getCategory(allTranslatedNames); + if (category != null) { + poiTypeTextInputLayout.setHint(category.getTranslation()); + } + } + }); + poiTypeEditText.setText(text != null ? text : ""); + poiTypeEditText.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(final View v, MotionEvent event) { + final EditText editText = (EditText) v; + final int DRAWABLE_RIGHT = 2; + if (event.getAction() == MotionEvent.ACTION_UP) { + if (event.getX() >= (editText.getRight() + - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() + - editText.getPaddingRight())) { + PoiCategory category = getCategory(allTranslatedNames); + PoiCategory tempPoiCategory= (category != null) ? category : poiTypes.getOtherPoiCategory(); + PoiSubTypeDialogFragment f = + PoiSubTypeDialogFragment.createInstance(tempPoiCategory); + f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() { + @Override + public void select(String category) { + poiTypeEditText.setText(category); + } + }); + + CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG); + f.show(parentFragment.getChildFragmentManager(), "PoiSubTypeDialogFragment"); + + return true; + } + } + return false; + } + }); + + setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText); + + ImageButton onlineDocumentationButton = + (ImageButton) view.findViewById(R.id.onlineDocumentationButton); + onlineDocumentationButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + activity.startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features"))); + } + }); + + boolean isLightTheme = activity.getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; + final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark; + final int color = activity.getResources().getColor(colorId); + onlineDocumentationButton.setImageDrawable(activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_help, color)); +// poiTypeEditText.setCompoundDrawables(null, null, activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_arrow_drop_down, color), null); + +// Button addTypeButton = (Button) view.findViewById(R.id.addTypeButton); +// addTypeButton.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(poiTypes.getOtherPoiCategory()); +// f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() { +// @Override +// public void select(String category) { +// putTagIntoParams(POI_TYPE_TAG, category); +// } +// }); +// +// CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG); +// f.show(parentFragment.getChildFragmentManager(), "PoiSubTypeDialogFragment"); +// } +// }); + parent.addView(view); } + private void setUpAdapterForPoiTypeEditText(final MapActivity activity, final Map allTranslatedNames, final AutoCompleteTextView poiTypeEditText) { + final Map subCategories = new LinkedHashMap<>(); +// PoiCategory ct = editPoiData.getPoiCategory(); +// if (ct != null) { +// for (PoiType s : ct.getPoiTypes()) { +// if (!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) { +// addMapEntryAdapter(subCategories, s.getTranslation(), s); +// if(!s.getKeyName().contains("osmand")) { +// addMapEntryAdapter(subCategories, s.getKeyName().replace('_', ' '), s); +// } +// } +// } +// } + for (Entry s : allTranslatedNames.entrySet()) { + addMapEntryAdapter(subCategories, s.getKey(), s.getValue()); + } + final ArrayAdapter adapter; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + adapter = new ArrayAdapter<>(activity, + R.layout.list_textview, subCategories.keySet().toArray()); + } else { + TypedValue typedValue = new TypedValue(); + Resources.Theme theme = activity.getTheme(); + theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true); + final int textColor = typedValue.data; + + adapter = new ArrayAdapter(activity, + R.layout.list_textview, subCategories.keySet().toArray()) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { + final View view = super.getView(position, convertView, parent); + ((TextView) view.findViewById(R.id.textView)).setTextColor(textColor); + return view; + } + }; + } + adapter.sort(new Comparator() { + @Override + public int compare(Object lhs, Object rhs) { + return lhs.toString().compareTo(rhs.toString()); + } + }); + poiTypeEditText.setAdapter(adapter); + poiTypeEditText.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + Object item = parent.getAdapter().getItem(position); + poiTypeEditText.setText(item.toString()); + setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText); + } + + @Override + public void onNothingSelected(AdapterView parent) { + } + }); + } + + private PoiCategory getCategory(Map allTranslatedNames) { + String tp = getTagsFromParams().get(POI_TYPE_TAG); + PoiType pt = allTranslatedNames.get(tp.toLowerCase()); + if (pt != null) { + return pt.getCategory(); + } else + return null; + } + + private void addMapEntryAdapter(final Map subCategories, String key, PoiType v) { + if (!subCategories.containsKey(key.toLowerCase())) { + subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(key), v); + } + } + private class TagAdapterLinearLayoutHack { private final LinearLayout linearLayout; private final Map tagsData; @@ -1538,8 +1721,8 @@ public class QuickActionFactory { linearLayout.removeAllViews(); List> entries = new ArrayList<>(tagsData.entrySet()); for (Entry tag : entries) { - if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG) - || tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue())) + if (tag.getKey().equals(POI_TYPE_TAG) + /*|| tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue())*/) continue; addTagView(tag.getKey(), tag.getValue()); } @@ -1656,6 +1839,12 @@ public class QuickActionFactory { private void setTagsIntoParams(Map tags) { getParams().put(KEY_TAG, new Gson().toJson(tags)); } + + private void putTagIntoParams(String tag, String value) { + Map tagsFromParams = getTagsFromParams(); + tagsFromParams.put(tag, value); + setTagsIntoParams(tagsFromParams); + } } public static class MapStyleAction extends SwitchableAction {