Search in sources :

Example 1 with ExtendedEditText

use of studio.carbonylgroup.textfieldboxes.ExtendedEditText 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)

Aggregations

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 Gravity (android.view.Gravity)1 KeyEvent (android.view.KeyEvent)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1