use of net.osmand.plus.plugins.osmedit.EditPoiViewPager 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;
}
Aggregations