Merge pull request #7915 from osmandapp/Issue_7224
Issue #7224 Show POI category icons for Add POI quick action
This commit is contained in:
commit
2a560f26df
1 changed files with 38 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.quickaction.actions;
|
package net.osmand.plus.quickaction.actions;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
@ -36,7 +37,6 @@ import net.osmand.osm.edit.Entity;
|
||||||
import net.osmand.osm.edit.Node;
|
import net.osmand.osm.edit.Node;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.OsmandSettings;
|
|
||||||
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.osmedit.EditPoiData;
|
import net.osmand.plus.osmedit.EditPoiData;
|
||||||
|
@ -49,6 +49,7 @@ import net.osmand.plus.osmedit.OsmPoint;
|
||||||
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
|
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
|
||||||
import net.osmand.plus.quickaction.CreateEditActionDialog;
|
import net.osmand.plus.quickaction.CreateEditActionDialog;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
@ -70,6 +71,8 @@ public class AddPOIAction extends QuickAction {
|
||||||
|
|
||||||
private transient EditText title;
|
private transient EditText title;
|
||||||
private transient String prevType = "";
|
private transient String prevType = "";
|
||||||
|
private transient MapPoiTypes poiTypes;
|
||||||
|
private transient Map<String, PoiType> allTranslatedNames;
|
||||||
|
|
||||||
public AddPOIAction() {
|
public AddPOIAction() {
|
||||||
super(TYPE);
|
super(TYPE);
|
||||||
|
@ -79,6 +82,34 @@ public class AddPOIAction extends QuickAction {
|
||||||
super(quickAction);
|
super(quickAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MapPoiTypes getPoiTypes(Context context) {
|
||||||
|
if (poiTypes == null) {
|
||||||
|
final OsmandApplication application = (OsmandApplication) (context).getApplicationContext();
|
||||||
|
poiTypes = application.getPoiTypes();
|
||||||
|
}
|
||||||
|
return poiTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, PoiType> getAllTranslatedNames(Context context) {
|
||||||
|
if (allTranslatedNames == null) {
|
||||||
|
allTranslatedNames = getPoiTypes(context).getAllTranslatedNames(true);
|
||||||
|
}
|
||||||
|
return allTranslatedNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconRes(Context context) {
|
||||||
|
PoiCategory category = getCategory(getAllTranslatedNames(context));
|
||||||
|
if (category != null) {
|
||||||
|
category.getIconKeyName();
|
||||||
|
String res = category.getIconKeyName();
|
||||||
|
if (res != null && RenderingIcons.containsBigIcon(res)) {
|
||||||
|
return RenderingIcons.getBigIconResourceId(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.getIconRes();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(final MapActivity activity) {
|
public void execute(final MapActivity activity) {
|
||||||
|
|
||||||
|
@ -182,17 +213,14 @@ public class AddPOIAction extends QuickAction {
|
||||||
final LinearLayout editTagsLineaLayout =
|
final LinearLayout editTagsLineaLayout =
|
||||||
(LinearLayout) view.findViewById(R.id.editTagsList);
|
(LinearLayout) view.findViewById(R.id.editTagsList);
|
||||||
|
|
||||||
final MapPoiTypes poiTypes = application.getPoiTypes();
|
|
||||||
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(true);
|
|
||||||
final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable);
|
final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable);
|
||||||
// It is possible to not restart initialization every time, and probably move initialization to appInit
|
// It is possible to not restart initialization every time, and probably move initialization to appInit
|
||||||
Map<String, PoiType> translatedTypes = poiTypes.getAllTranslatedNames(true);
|
|
||||||
HashSet<String> tagKeys = new HashSet<>();
|
HashSet<String> tagKeys = new HashSet<>();
|
||||||
HashSet<String> valueKeys = new HashSet<>();
|
HashSet<String> valueKeys = new HashSet<>();
|
||||||
for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
|
for (AbstractPoiType abstractPoiType : getAllTranslatedNames(application).values()) {
|
||||||
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
|
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
|
||||||
}
|
}
|
||||||
addPoiToStringSet(poiTypes.getOtherMapCategory(), tagKeys, valueKeys);
|
addPoiToStringSet(getPoiTypes(activity).getOtherMapCategory(), tagKeys, valueKeys);
|
||||||
tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS);
|
tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS);
|
||||||
mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
|
mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
|
||||||
mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
|
mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
|
||||||
|
@ -237,7 +265,7 @@ public class AddPOIAction extends QuickAction {
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
String tp = s.toString();
|
String tp = s.toString();
|
||||||
putTagIntoParams(POI_TYPE_TAG, tp);
|
putTagIntoParams(POI_TYPE_TAG, tp);
|
||||||
PoiCategory category = getCategory(allTranslatedNames);
|
PoiCategory category = getCategory(getAllTranslatedNames(application));
|
||||||
|
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
poiTypeTextInputLayout.setHint(category.getTranslation());
|
poiTypeTextInputLayout.setHint(category.getTranslation());
|
||||||
|
@ -270,8 +298,8 @@ public class AddPOIAction extends QuickAction {
|
||||||
if (event.getX() >= (editText.getRight()
|
if (event.getX() >= (editText.getRight()
|
||||||
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
||||||
- editText.getPaddingRight())) {
|
- editText.getPaddingRight())) {
|
||||||
PoiCategory category = getCategory(allTranslatedNames);
|
PoiCategory category = getCategory(getAllTranslatedNames(activity));
|
||||||
PoiCategory tempPoiCategory = (category != null) ? category : poiTypes.getOtherPoiCategory();
|
PoiCategory tempPoiCategory = (category != null) ? category : getPoiTypes(activity).getOtherPoiCategory();
|
||||||
PoiSubTypeDialogFragment f =
|
PoiSubTypeDialogFragment f =
|
||||||
PoiSubTypeDialogFragment.createInstance(tempPoiCategory);
|
PoiSubTypeDialogFragment.createInstance(tempPoiCategory);
|
||||||
f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
|
f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
|
||||||
|
@ -291,7 +319,7 @@ public class AddPOIAction extends QuickAction {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText);
|
setUpAdapterForPoiTypeEditText(activity, getAllTranslatedNames(activity), poiTypeEditText);
|
||||||
|
|
||||||
ImageButton onlineDocumentationButton =
|
ImageButton onlineDocumentationButton =
|
||||||
(ImageButton) view.findViewById(R.id.onlineDocumentationButton);
|
(ImageButton) view.findViewById(R.id.onlineDocumentationButton);
|
||||||
|
|
Loading…
Reference in a new issue