use of net.osmand.plus.quickaction.CreateEditActionDialog in project Osmand by osmandapp.
the class AddPOIAction method drawUI.
@Override
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);
final OsmandApplication application = activity.getMyApplication();
Drawable deleteDrawable = application.getIconsCache().getPaintedIcon(R.drawable.ic_action_remove_dark, activity.getResources().getColor(R.color.dash_search_icon_dark));
final LinearLayout editTagsLineaLayout = (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);
// 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> valueKeys = new HashSet<>();
for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
addPoiToStringSet(abstractPoiType, 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()]));
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
addTagButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < editTagsLineaLayout.getChildCount(); i++) {
View item = editTagsLineaLayout.getChildAt(i);
if (((EditText) item.findViewById(R.id.tagEditText)).getText().toString().isEmpty() && ((EditText) item.findViewById(R.id.valueEditText)).getText().toString().isEmpty())
return;
}
mAdapter.addTagView("", "");
}
});
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)));
final 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());
}
String add = application.getString(R.string.shared_string_add);
if (title != null) {
if (prevType.equals(title.getText().toString()) || title.getText().toString().equals(activity.getString(getNameRes())) || title.getText().toString().equals((add + " "))) {
if (!tp.isEmpty()) {
title.setText(add + " " + tp);
prevType = title.getText().toString();
}
}
}
}
});
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(activity.getSupportFragmentManager(), "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);
}
Aggregations