From c95348658f16b2ad0a53d5fb6d8a721428328a5d Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 19 Oct 2017 19:10:28 +0300 Subject: [PATCH] Add fragment for renaming marker --- ...ment_rename_marker_bottom_sheet_dialog.xml | 80 ++++++++++ OsmAnd/res/values/strings.xml | 1 + .../mapmarkers/MarkerMenuOnMapFragment.java | 9 +- ...RenameMarkerBottomSheetDialogFragment.java | 141 ++++++++++++++++++ 4 files changed, 229 insertions(+), 2 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_rename_marker_bottom_sheet_dialog.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/RenameMarkerBottomSheetDialogFragment.java diff --git a/OsmAnd/res/layout/fragment_rename_marker_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_rename_marker_bottom_sheet_dialog.xml new file mode 100644 index 0000000000..8e91d69c52 --- /dev/null +++ b/OsmAnd/res/layout/fragment_rename_marker_bottom_sheet_dialog.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 9ac72f6a80..43fe81569e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Enter new name Back Wrong format Road diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerMenuOnMapFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerMenuOnMapFragment.java index 934a759b5a..711c871cde 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerMenuOnMapFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkerMenuOnMapFragment.java @@ -16,7 +16,6 @@ import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; -import android.widget.Toast; import net.osmand.Location; import net.osmand.data.LatLon; @@ -133,7 +132,13 @@ public class MarkerMenuOnMapFragment extends Fragment implements OsmAndCompassLi mainView.findViewById(R.id.rename_row).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Toast.makeText(getContext(), "Rename", Toast.LENGTH_SHORT).show(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + RenameMarkerBottomSheetDialogFragment fragment = new RenameMarkerBottomSheetDialogFragment(); + fragment.setMarker(marker); + fragment.setRetainInstance(true); + fragment.show(mapActivity.getSupportFragmentManager(), RenameMarkerBottomSheetDialogFragment.TAG); + } } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/RenameMarkerBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/RenameMarkerBottomSheetDialogFragment.java new file mode 100644 index 0000000000..f0191ed619 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/RenameMarkerBottomSheetDialogFragment.java @@ -0,0 +1,141 @@ +package net.osmand.plus.mapmarkers; + +import android.app.Dialog; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.ContextThemeWrapper; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.Window; +import android.view.WindowManager; +import android.widget.EditText; +import android.widget.LinearLayout; + +import net.osmand.AndroidUtils; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandTextFieldBoxes; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; + +public class RenameMarkerBottomSheetDialogFragment extends BottomSheetDialogFragment { + + public final static String TAG = "RenameMarkerBottomSheetDialogFragment"; + + private MapMarker marker; + + public void setMarker(MapMarker marker) { + this.marker = marker; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + MapActivity mapActivity = (MapActivity) getActivity(); + final boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_rename_marker_bottom_sheet_dialog, container); + + LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout); + int layoutRes = Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH + ? R.layout.markers_track_name_text_field_box + : R.layout.markers_track_name_edit_text; + contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 1); + + if (portrait) { + AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } + + final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text); + nameEditText.setText(marker.getName(mapActivity)); + View textBox = mainView.findViewById(R.id.name_text_box); + if (textBox instanceof OsmandTextFieldBoxes) { + ((OsmandTextFieldBoxes) textBox).activate(true); + } + + mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + mainView.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + final int screenHeight = AndroidUtils.getScreenHeight(getActivity()); + final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity()); + final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity()); + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + + boolean dimensSet; + + @Override + public void onGlobalLayout() { + if (!dimensSet) { + final View scrollView = mainView.findViewById(R.id.rename_marker_scroll_view); + int scrollViewHeight = scrollView.getHeight(); + int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; + if (scrollViewHeight > spaceForScrollView) { + scrollView.getLayoutParams().height = spaceForScrollView; + scrollView.requestLayout(); + } + + if (!portrait) { + if (screenHeight - statusBarHeight - mainView.getHeight() + >= AndroidUtils.dpToPx(getActivity(), 8)) { + AndroidUtils.setBackground(getActivity(), mainView, nightMode, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(getActivity(), mainView, nightMode, + R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark); + } + } + dimensSet = true; + } + + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.height = ViewGroup.LayoutParams.WRAP_CONTENT; + params.gravity = Gravity.BOTTOM; + window.setAttributes(params); + } + }); + + return mainView; + } + + @Override + public void onStart() { + super.onStart(); + if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + window.setAttributes(params); + } + } + + @Override + public void onDestroyView() { + Dialog dialog = getDialog(); + if (dialog != null && getRetainInstance()) { + dialog.setDismissMessage(null); + } + super.onDestroyView(); + } +}