Search in sources :

Example 1 with PoiTypeDialogFragment

use of net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment 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)1 TabLayout (android.support.design.widget.TabLayout)1 ViewPager (android.support.v4.view.ViewPager)1 Toolbar (android.support.v7.widget.Toolbar)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)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 TextView (android.widget.TextView)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 PoiCategory (net.osmand.osm.PoiCategory)1 PoiSubTypeDialogFragment (net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment)1 PoiTypeDialogFragment (net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment)1