Search in sources :

Example 1 with CreateEditActionDialog

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);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) PoiSubTypeDialogFragment(net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) HashSet(java.util.HashSet) EditText(android.widget.EditText) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AbstractPoiType(net.osmand.osm.AbstractPoiType) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapPoiTypes(net.osmand.osm.MapPoiTypes) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint) MotionEvent(android.view.MotionEvent) CreateEditActionDialog(net.osmand.plus.quickaction.CreateEditActionDialog) PoiCategory(net.osmand.osm.PoiCategory) LinearLayout(android.widget.LinearLayout) AutoCompleteTextView(android.widget.AutoCompleteTextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

Intent (android.content.Intent)1 Drawable (android.graphics.drawable.Drawable)1 TextInputLayout (android.support.design.widget.TextInputLayout)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 ImageButton (android.widget.ImageButton)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 HashSet (java.util.HashSet)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 MapPoiTypes (net.osmand.osm.MapPoiTypes)1 PoiCategory (net.osmand.osm.PoiCategory)1 PoiType (net.osmand.osm.PoiType)1