Search in sources :

Example 1 with PoiSubTypeDialogFragment

use of net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment 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)

Example 2 with PoiSubTypeDialogFragment

use of net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment in project Osmand by osmandapp.

the class EditPoiDialogFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_edit_poi, container, false);
    boolean isLightTheme = getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
    if (savedInstanceState != null) {
        @SuppressWarnings("unchecked") Map<String, String> mp = (Map<String, String>) savedInstanceState.getSerializable(TAGS_LIST);
        editPoiData.updateTags(mp);
    }
    boolean isAddingPoi = getArguments().getBoolean(IS_ADDING_POI);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setTitle(isAddingPoi ? R.string.poi_create_title : R.string.poi_edit_title);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
    toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissCheckForChanges();
        }
    });
    viewPager = (ViewPager) view.findViewById(R.id.viewpager);
    String basicTitle = getResources().getString(R.string.tab_title_basic);
    String extendedTitle = getResources().getString(R.string.tab_title_advanced);
    final MyAdapter pagerAdapter = new MyAdapter(getChildFragmentManager(), basicTitle, extendedTitle);
    viewPager.setAdapter(pagerAdapter);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int i, float v, int i1) {
        }

        @Override
        public void onPageSelected(int i) {
            ((OnFragmentActivatedListener) pagerAdapter.getItem(i)).onFragmentActivated();
        }

        @Override
        public void onPageScrollStateChanged(int i) {
        }
    });
    final TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    // TODO remove in new version
    if (Build.VERSION.SDK_INT >= 11) {
        if (ViewCompat.isLaidOut(tabLayout)) {
            tabLayout.setupWithViewPager(viewPager);
        } else {
            tabLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    tabLayout.setupWithViewPager(viewPager);
                    tabLayout.removeOnLayoutChangeListener(this);
                }
            });
        }
    } else {
        ViewTreeObserver vto = view.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {
                ViewTreeObserver obs = view.getViewTreeObserver();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    obs.removeGlobalOnLayoutListener(this);
                }
                if (getActivity() != null) {
                    tabLayout.setupWithViewPager(viewPager);
                }
            }
        });
    }
    ImageButton onlineDocumentationButton = (ImageButton) view.findViewById(R.id.onlineDocumentationButton);
    onlineDocumentationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
        }
    });
    final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark;
    final int color = getResources().getColor(colorId);
    onlineDocumentationButton.setImageDrawable(getPaintedContentIcon(R.drawable.ic_action_help, color));
    final ImageButton poiTypeButton = (ImageButton) view.findViewById(R.id.poiTypeButton);
    poiTypeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PoiTypeDialogFragment fragment = PoiTypeDialogFragment.createInstance();
            fragment.setOnItemSelectListener(new PoiTypeDialogFragment.OnItemSelectListener() {

                @Override
                public void select(PoiCategory poiCategory) {
                    setPoiCategory(poiCategory);
                }
            });
            fragment.show(getChildFragmentManager(), "PoiTypeDialogFragment");
        }
    });
    EditText poiNameEditText = (EditText) view.findViewById(R.id.poiNameEditText);
    poiNameEditText.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) {
            if (!getEditPoiData().isInEdit()) {
                if (!TextUtils.isEmpty(s)) {
                    getEditPoiData().putTag(OSMSettings.OSMTagKey.NAME.getValue(), s.toString());
                } else {
                    getEditPoiData().removeTag(OSMSettings.OSMTagKey.NAME.getValue());
                }
            }
        }
    });
    poiNameEditText.setText(editPoiData.getTag(OSMSettings.OSMTagKey.NAME.getValue()));
    poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
    poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
    poiTypeEditText.setText(editPoiData.getPoiTypeString());
    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) {
            if (!getEditPoiData().isInEdit()) {
                getEditPoiData().updateTypeTag(s.toString(), true);
                if (!getMyApplication().isApplicationInitializing()) {
                    poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
                }
            }
        }
    });
    poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
    poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
    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())) {
                    if (editPoiData.getPoiCategory() != null) {
                        PoiSubTypeDialogFragment dialogFragment = PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
                        dialogFragment.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {

                            @Override
                            public void select(String category) {
                                setSubCategory(category);
                            }
                        });
                        dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
                    }
                    return true;
                }
            }
            return false;
        }
    });
    if (!isAddingPoi) {
        Button deleteButton = (Button) view.findViewById(R.id.deleteButton);
        deleteButton.setVisibility(View.VISIBLE);
        deleteButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                DeletePoiHelper deletePoiHelper = new DeletePoiHelper(getMyActivity());
                deletePoiHelper.setCallback(new DeletePoiHelper.DeletePoiCallback() {

                    @Override
                    public void poiDeleted() {
                        dismiss();
                    }
                });
                deletePoiHelper.deletePoiWithDialog(getEditPoiData().getEntity());
            }
        });
    }
    Button saveButton = (Button) view.findViewById(R.id.saveButton);
    saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            trySave();
        }
    });
    Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
    cancelButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissCheckForChanges();
        }
    });
    setAdapterForPoiTypeEditText();
    setCancelable(false);
    return view;
}
Also used : ImageButton(android.widget.ImageButton) PoiSubTypeDialogFragment(net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment) ImageButton(android.widget.ImageButton) Button(android.widget.Button) TabLayout(android.support.design.widget.TabLayout) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ViewTreeObserver(android.view.ViewTreeObserver) Toolbar(android.support.v7.widget.Toolbar) EditText(android.widget.EditText) PoiTypeDialogFragment(net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) ViewPager(android.support.v4.view.ViewPager) MotionEvent(android.view.MotionEvent) PoiCategory(net.osmand.osm.PoiCategory) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Intent (android.content.Intent)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 ImageButton (android.widget.ImageButton)2 TextView (android.widget.TextView)2 PoiCategory (net.osmand.osm.PoiCategory)2 PoiSubTypeDialogFragment (net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment)2 Drawable (android.graphics.drawable.Drawable)1 TabLayout (android.support.design.widget.TabLayout)1 TextInputLayout (android.support.design.widget.TextInputLayout)1 ViewPager (android.support.v4.view.ViewPager)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 Toolbar (android.support.v7.widget.Toolbar)1 ViewTreeObserver (android.view.ViewTreeObserver)1