Search in sources :

Example 1 with OpenstreetmapRemoteUtil

use of net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil 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().isLightContent();
    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);
    Drawable icBack = getMyApplication().getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(getContext()));
    toolbar.setNavigationIcon(icBack);
    toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismissCheckForChanges();
        }
    });
    viewPager = (EditPoiViewPager) view.findViewById(R.id.viewpager);
    String basicTitle = getResources().getString(R.string.tab_title_basic);
    String extendedTitle = getResources().getString(R.string.tab_title_advanced);
    final PoiInfoPagerAdapter pagerAdapter = new PoiInfoPagerAdapter(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) {
            Fragment pageFragment = pagerAdapter.getItem(i);
            ((OnFragmentActivatedListener) pageFragment).onFragmentActivated();
            if (pageFragment instanceof OnSaveButtonClickListener) {
                onSaveButtonClickListener = (OnSaveButtonClickListener) pageFragment;
            } else {
                onSaveButtonClickListener = null;
            }
        }

        @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() {
                if (getActivity() != null) {
                    tabLayout.setupWithViewPager(viewPager);
                }
            }
        });
    }
    ImageButton onlineDocumentationButton = view.findViewById(R.id.onlineDocumentationButton);
    onlineDocumentationButton.setOnClickListener(v -> {
        Activity activity = getActivity();
        if (activity != null) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features"));
            AndroidUtils.startActivityIfSafe(activity, intent);
        }
    });
    final int activeColor = ColorUtilities.getActiveColor(getContext(), !isLightTheme);
    onlineDocumentationButton.setImageDrawable(getPaintedContentIcon(R.drawable.ic_action_help, activeColor));
    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");
        }
    });
    ExtendedEditText poiNameEditText = (ExtendedEditText) view.findViewById(R.id.poiNameEditText);
    AndroidUtils.setTextHorizontalGravity(poiNameEditText, Gravity.START);
    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()));
    poiNameEditText.requestFocus();
    AndroidUtils.showSoftKeyboard(getActivity(), poiNameEditText);
    poiTypeTextInputLayout = (OsmandTextFieldBoxes) view.findViewById(R.id.poiTypeTextInputLayout);
    poiTypeEditText = (ExtendedEditText) view.findViewById(R.id.poiTypeEditText);
    AndroidUtils.setTextHorizontalGravity(poiTypeEditText, Gravity.START);
    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()) {
                    PoiCategory category = editPoiData.getPoiCategory();
                    if (category != null) {
                        poiTypeTextInputLayout.setLabelText(category.getTranslation());
                    }
                }
            }
        }
    });
    poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
    poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
    AppCompatImageButton expandButton = poiTypeTextInputLayout.getEndIconImageButton();
    expandButton.setColorFilter(R.color.gpx_chart_red);
    expandButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PoiCategory category = editPoiData.getPoiCategory();
            if (category != null) {
                PoiSubTypeDialogFragment dialogFragment = PoiSubTypeDialogFragment.createInstance(category);
                dialogFragment.setOnItemSelectListener(c -> setSubCategory(c));
                dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
            }
        }
    });
    if (!isAddingPoi && Entity.EntityType.valueOf(editPoiData.getEntity()) == Entity.EntityType.NODE) {
        Button deleteButton = (Button) view.findViewById(R.id.deleteButton);
        deleteButton.setVisibility(View.VISIBLE);
        deleteButton.setOnClickListener(v -> {
            DeletePoiHelper deletePoiHelper = new DeletePoiHelper(getMyActivity());
            deletePoiHelper.setCallback(this::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);
    if (editPoiData.hasEmptyValue()) {
        viewPager.setCurrentItem(ADVANCED_TAB);
    }
    editPoiData.setupInitPoint();
    return view;
}
Also used : ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) WindowManager(android.view.WindowManager) R(net.osmand.plus.R) BaseOsmAndDialogFragment(net.osmand.plus.base.BaseOsmAndDialogFragment) Drawable(android.graphics.drawable.Drawable) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) EntityInfo(net.osmand.osm.edit.EntityInfo) UiUtilities(net.osmand.plus.utils.UiUtilities) CallbackWithObject(net.osmand.CallbackWithObject) CheckBox(android.widget.CheckBox) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) Amenity(net.osmand.data.Amenity) AdapterView(android.widget.AdapterView) ViewCompat(androidx.core.view.ViewCompat) OpenstreetmapUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil) Node(net.osmand.osm.edit.Node) PoiCategory(net.osmand.osm.PoiCategory) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) AsyncTask(android.os.AsyncTask) TabLayout(com.google.android.material.tabs.TabLayout) Set(java.util.Set) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ViewGroup(android.view.ViewGroup) OsmandApplication(net.osmand.plus.OsmandApplication) Serializable(java.io.Serializable) OsmandPlugin(net.osmand.plus.plugins.OsmandPlugin) Way(net.osmand.osm.edit.Way) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Entry(java.util.Map.Entry) Toolbar(androidx.appcompat.widget.Toolbar) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) EditorInfo(android.view.inputmethod.EditorInfo) TextWatcher(android.text.TextWatcher) Context(android.content.Context) MapObject(net.osmand.data.MapObject) KeyEvent(android.view.KeyEvent) AlertDialog(androidx.appcompat.app.AlertDialog) AdvancedEditPoiFragment(net.osmand.plus.plugins.osmedit.fragments.AdvancedEditPoiFragment) ColorUtilities(net.osmand.plus.utils.ColorUtilities) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) Intent(android.content.Intent) EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) Editable(android.text.Editable) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) LatLon(net.osmand.data.LatLon) PoiType(net.osmand.osm.PoiType) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) Toast(android.widget.Toast) PlatformUtil(net.osmand.PlatformUtil) Build(android.os.Build) Algorithms(net.osmand.util.Algorithms) DialogInterface(android.content.DialogInterface) AndroidUtils(net.osmand.plus.utils.AndroidUtils) FragmentManager(androidx.fragment.app.FragmentManager) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) Entity(net.osmand.osm.edit.Entity) ExtendedEditText(studio.carbonylgroup.textfieldboxes.ExtendedEditText) LayoutInflater(android.view.LayoutInflater) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) POI_TYPE_TAG(net.osmand.osm.edit.Entity.POI_TYPE_TAG) OSMSettings(net.osmand.osm.edit.OSMSettings) FragmentPagerAdapter(androidx.fragment.app.FragmentPagerAdapter) Gravity(android.view.Gravity) ArrayAdapter(android.widget.ArrayAdapter) BasicEditPoiFragment(net.osmand.plus.plugins.osmedit.fragments.BasicEditPoiFragment) TypedValue(android.util.TypedValue) EditPoiViewPager(net.osmand.plus.plugins.osmedit.EditPoiViewPager) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) ViewTreeObserver(android.view.ViewTreeObserver) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) Log(org.apache.commons.logging.Log) OsmandTextFieldBoxes(net.osmand.plus.widgets.OsmandTextFieldBoxes) Comparator(java.util.Comparator) Activity(android.app.Activity) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) MapActivity(net.osmand.plus.activities.MapActivity) ExtendedEditText(studio.carbonylgroup.textfieldboxes.ExtendedEditText) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Activity(android.app.Activity) MapActivity(net.osmand.plus.activities.MapActivity) BaseOsmAndDialogFragment(net.osmand.plus.base.BaseOsmAndDialogFragment) Fragment(androidx.fragment.app.Fragment) AdvancedEditPoiFragment(net.osmand.plus.plugins.osmedit.fragments.AdvancedEditPoiFragment) BasicEditPoiFragment(net.osmand.plus.plugins.osmedit.fragments.BasicEditPoiFragment) ImageButton(android.widget.ImageButton) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) TabLayout(com.google.android.material.tabs.TabLayout) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) ViewTreeObserver(android.view.ViewTreeObserver) Toolbar(androidx.appcompat.widget.Toolbar) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ViewPager(androidx.viewpager.widget.ViewPager) EditPoiViewPager(net.osmand.plus.plugins.osmedit.EditPoiViewPager) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) PoiCategory(net.osmand.osm.PoiCategory) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with OpenstreetmapRemoteUtil

use of net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil in project Osmand by osmandapp.

the class EditPoiDialogFragment method save.

public void save() {
    Entity original = editPoiData.getEntity();
    final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
    Entity entity;
    if (original instanceof Node) {
        entity = new Node(original.getLatitude(), original.getLongitude(), original.getId());
    } else if (original instanceof Way) {
        entity = new Way(original.getId(), ((Way) original).getNodeIds(), original.getLatitude(), original.getLongitude());
    } else {
        return;
    }
    Action action = entity.getId() < 0 ? Action.CREATE : Action.MODIFY;
    for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
        if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && !tag.getKey().equals(POI_TYPE_TAG)) {
            entity.putTagNoLC(tag.getKey(), tag.getValue());
        }
    }
    String poiTypeTag = editPoiData.getTagValues().get(POI_TYPE_TAG);
    String comment = "";
    if (poiTypeTag != null) {
        final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
        if (poiType != null) {
            entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
            entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
            if (poiType.getOsmTag2() != null) {
                entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
            }
            if (poiType.getEditOsmTag2() != null) {
                entity.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag2());
            }
        } else if (!Algorithms.isEmpty(poiTypeTag)) {
            PoiCategory category = editPoiData.getPoiCategory();
            if (category != null) {
                entity.putTagNoLC(category.getDefaultTag(), poiTypeTag);
            }
        }
        if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
            entity.putTagNoLC(POI_TYPE_TAG, poiTypeTag);
        }
        String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
        comment = actionString + " " + poiTypeTag;
    }
    commitEntity(action, entity, mOpenstreetmapUtil.getEntityInfo(entity.getId()), comment, false, result -> {
        OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        if (result != null) {
            if (offlineEdit) {
                List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
                if (getActivity() instanceof MapActivity && points.size() > 0) {
                    OsmPoint point = points.get(points.size() - 1);
                    MapActivity mapActivity = (MapActivity) getActivity();
                    mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
                    mapActivity.getMapLayers().getContextMenuLayer().updateContextMenu();
                }
            }
            if (getActivity() instanceof MapActivity) {
                ((MapActivity) getActivity()).getMapView().refreshMap(true);
            }
            dismissAllowingStateLoss();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
            Button saveButton = view.findViewById(R.id.saveButton);
            saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
        }
        return false;
    }, getActivity(), mOpenstreetmapUtil, action == Action.MODIFY ? editPoiData.getChangedTags() : null);
}
Also used : Entity(net.osmand.osm.edit.Entity) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) Way(net.osmand.osm.edit.Way) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) LatLon(net.osmand.data.LatLon) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) PoiCategory(net.osmand.osm.PoiCategory) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MapActivity(net.osmand.plus.activities.MapActivity)

Example 3 with OpenstreetmapRemoteUtil

use of net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil in project Osmand by osmandapp.

the class UploadGPXFilesTask method doInBackground.

@Override
protected String doInBackground(GpxInfo... params) {
    int count = 0;
    int total = 0;
    for (GpxInfo info : params) {
        if (!isCancelled() && info.file != null) {
            File file = info.file;
            OpenstreetmapRemoteUtil remoteUtil = new OpenstreetmapRemoteUtil(app);
            String gpxDescription = Algorithms.isEmpty(commonDescription.trim()) ? Algorithms.getFileNameWithoutExtension(info.getFileName()) : commonDescription;
            String warning = remoteUtil.uploadGPXFile(tags, gpxDescription, visibility, file);
            total++;
            if (warning == null) {
                count++;
            } else {
                publishProgress(warning);
            }
        }
    }
    return app.getString(R.string.local_index_items_uploaded, count, total);
}
Also used : OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) GpxInfo(net.osmand.plus.myplaces.ui.AvailableGPXFragment.GpxInfo) File(java.io.File)

Aggregations

Button (android.widget.Button)2 ImageButton (android.widget.ImageButton)2 AppCompatImageButton (androidx.appcompat.widget.AppCompatImageButton)2 OpenstreetmapRemoteUtil (net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 ProgressDialog (android.app.ProgressDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Editable (android.text.Editable)1 TextUtils (android.text.TextUtils)1 TextWatcher (android.text.TextWatcher)1 TypedValue (android.util.TypedValue)1