From 0c2056f7c519c5b280eee36cc03da3102956924f Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 15 Jun 2018 14:24:09 +0300 Subject: [PATCH 01/19] add CoordinateInputActionsBottomSheet --- .../CoordinateInputActionsBottomSheet.java | 75 +++++++++++++++++++ .../CoordinateInputDialogFragment.java | 35 +++++++++ .../adapters/CoordinateInputAdapter.java | 35 ++++----- 3 files changed, 124 insertions(+), 21 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java new file mode 100644 index 0000000000..2746466fe6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java @@ -0,0 +1,75 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Bundle; +import android.view.View; + +import net.osmand.plus.R; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter; + +public class CoordinateInputActionsBottomSheet extends MenuBottomSheetDialogFragment { + + public final static String TAG = "CoordinateInputActionsBottomSheet"; + + private CoordinateInputActionsListener listener; + + public void setListener(CoordinateInputActionsListener listener) { + this.listener = listener; + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + Bundle args = getArguments(); + if (args == null) { + return; + } + final int position = args.getInt(CoordinateInputAdapter.ADAPTER_POSITION); + + items.add(new TitleItem(getString(R.string.shared_string_actions))); + + BaseBottomSheetItem editItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_type_edit)) + .setTitle(getString(R.string.shared_string_edit)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.editItem(position); + dismiss(); + } + }) + .create(); + items.add(editItem); + + BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_type_delete)) + .setTitle(getString(R.string.shared_string_delete)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + listener.removeItem(position); + dismiss(); + } + }) + .create(); + items.add(deleteItem); + + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } + + interface CoordinateInputActionsListener { + + void removeItem(int position); + + void editItem(int position); + + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 25eebb880f..aaf36d68e6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -296,6 +296,25 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm enterEditingMode(adapter.getItem(pos)); } }); + adapter.setOnActionsClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + RecyclerView.ViewHolder viewHolder = recyclerView.findContainingViewHolder(v); + if (viewHolder != null) { + int pos = viewHolder.getAdapterPosition(); + if (pos == RecyclerView.NO_POSITION) { + return; + } + Bundle args = new Bundle(); + args.putInt(CoordinateInputAdapter.ADAPTER_POSITION, pos); + CoordinateInputActionsBottomSheet fragment = new CoordinateInputActionsBottomSheet(); + fragment.setUsedOnMap(false); + fragment.setArguments(args); + fragment.setListener(createCoordinateInputActionsListener()); + fragment.show(getChildFragmentManager(), CoordinateInputActionsBottomSheet.TAG); + } + } + }); setBackgroundColor(R.id.bottom_controls_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.keyboard_item_control_dark_bg); @@ -884,6 +903,22 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm }; } + private CoordinateInputActionsBottomSheet.CoordinateInputActionsListener createCoordinateInputActionsListener() { + return new CoordinateInputActionsBottomSheet.CoordinateInputActionsListener() { + + @Override + public void removeItem(int position) { + adapter.removeItem(position); + } + + @Override + public void editItem(int position) { + enterEditingMode(adapter.getItem(position)); + } + + }; + } + private void changeHand() { dismissEditingMode(); ((FrameLayout) mainView.findViewById(R.id.left_container)).removeViewAt(0); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index 98a6727cda..268c574b77 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -22,6 +22,8 @@ import java.util.List; public class CoordinateInputAdapter extends RecyclerView.Adapter { + public static final String ADAPTER_POSITION = "position"; + private OsmandApplication app; private List mapMarkers; @@ -31,11 +33,16 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter mapMarkers) { this.app = app; this.mapMarkers = mapMarkers; @@ -61,23 +68,12 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter Date: Fri, 15 Jun 2018 18:15:49 +0300 Subject: [PATCH 02/19] add save as track function to coordinate input --- ...rker_save_as_track_bottom_sheet_dialog.xml | 1 + OsmAnd/res/values/strings.xml | 2 + .../src/net/osmand/plus/MapMarkersHelper.java | 23 +++++++++ ...rdinateInputBottomSheetDialogFragment.java | 22 +++++++++ .../CoordinateInputDialogFragment.java | 49 +++++++++++++++++++ .../SaveAsTrackBottomSheetDialogFragment.java | 13 +++++ 6 files changed, 110 insertions(+) diff --git a/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml index 6cdf00ddf6..7015872187 100644 --- a/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml +++ b/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml @@ -32,6 +32,7 @@ osmand:typeface="@string/font_roboto_medium"/> + Save as track + You added %1$s points. Enter the name of the file and click save. Please send screenshoot of this notification to support@osmand.net Edit actions Get OsmAnd Live to unlock all features: Daily map updates with unlimited downloads, all paid and free plugins, Wikipedia, Wikivoyage and much more. diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 6258455773..f76351fecd 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -1016,6 +1016,29 @@ public class MapMarkersHelper { GPXUtilities.writeGpxFile(fout, file, ctx); return fout.getAbsolutePath(); } + + public String generateGpxFromList(String fileName, List mapMarkers) { + final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); + if (!dir.exists()) { + dir.mkdirs(); + } + File fout = new File(dir, fileName + ".gpx"); + int ind = 1; + while (fout.exists()) { + fout = new File(dir, fileName + "_" + (++ind) + ".gpx"); + } + GPXFile file = new GPXFile(); + for (MapMarker marker : mapMarkers) { + WptPt wpt = new WptPt(); + wpt.lat = marker.getLatitude(); + wpt.lon = marker.getLongitude(); + wpt.setColor(ctx.getResources().getColor(MapMarker.getColorId(marker.colorIndex))); + wpt.name = marker.getOnlyName(); + file.addPoint(wpt); + } + GPXUtilities.writeGpxFile(fout, file, ctx); + return fout.getAbsolutePath(); + } // --------------------------------------------------------------------------------------------- diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 0b6ea87416..a1b1d669ea 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -12,6 +12,8 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleDividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; @@ -34,6 +36,24 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia final OsmandSettings settings = getMyApplication().getSettings(); items.add(new TitleItem(getString(R.string.shared_string_options))); + BaseBottomSheetItem editItem = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_save_to_file)) + .setTitle(getString(R.string.coord_input_save_as_track)) + .setLayoutId(R.layout.bottom_sheet_item_simple) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (listener != null) { + listener.saveAsTrack(); + } + dismiss(); + } + }) + .create(); + items.add(editItem); + + items.add(new DividerHalfItem(context)); + boolean useOsmandKeyboard = settings.COORDS_INPUT_USE_OSMAND_KEYBOARD.get(); BaseBottomSheetItem useSystemKeyboardItem = new BottomSheetItemWithCompoundButton.Builder() @@ -148,5 +168,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia void onHandChanged(); void onInputSettingsChanged(); + + void saveAsTrack(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index aaf36d68e6..ef21dae289 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -4,6 +4,7 @@ import android.app.Dialog; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; +import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -16,6 +17,7 @@ import android.support.annotation.DrawableRes; import android.support.annotation.IdRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.Snackbar; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; @@ -59,6 +61,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener; import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM; @@ -82,6 +85,7 @@ import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT; public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { public static final String TAG = "CoordinateInputDialogFragment"; + public static final String ADDED_MARKERS_NUMBER_KEY = "added_markers_number_key"; private final List mapMarkers = new ArrayList<>(); private MapMarker selectedMarker; @@ -91,6 +95,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private final List editTexts = new ArrayList<>(); private CoordinateInputAdapter adapter; private ImageView showHideKeyboardIcon; + private Snackbar snackbar; private boolean lightTheme; private boolean orientationPortrait; @@ -900,6 +905,50 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm dismissEditingMode(); registerInputs(); } + + @Override + public void saveAsTrack() { + OsmandApplication app = getMyApplication(); + if (app != null) { + if (mapMarkers.isEmpty()) { + Toast.makeText(app, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show(); + } else { + SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); + Bundle args = new Bundle(); + args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size()); + fragment.setArguments(args); + fragment.setListener(createSaveAsTrackFragmentListener()); + fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG); + } + } + + } + }; + } + + private SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener createSaveAsTrackFragmentListener() { + return new SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener() { + + final OsmandApplication app = getMyApplication(); + + @Override + public void saveGpx(final String fileName) { + final String gpxPath = app.getMapMarkersHelper().generateGpxFromList(fileName, mapMarkers); + + snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_show, new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(app, getMyApplication().getAppCustomization().getTrackActivity()); + intent.putExtra(TrackActivity.TRACK_FILE_NAME, gpxPath); + intent.putExtra(TrackActivity.OPEN_POINTS_TAB, true); + intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(intent); + } + }); + AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark); + snackbar.show(); + } }; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java index c2ca92ee08..1c8a143c82 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java @@ -17,6 +17,7 @@ import android.view.Window; import android.view.WindowManager; import android.widget.EditText; import android.widget.LinearLayout; +import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; @@ -30,6 +31,7 @@ import java.io.File; import java.util.Date; import static net.osmand.plus.helpers.ImportHelper.GPX_SUFFIX; +import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.ADDED_MARKERS_NUMBER_KEY; public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment { @@ -45,6 +47,13 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + boolean isCoordInput = false; + int number = 0; + if (getArguments() != null) { + number = getArguments().getInt(ADDED_MARKERS_NUMBER_KEY); + if (number != 0) + isCoordInput = true; + } MapActivity mapActivity = (MapActivity) getActivity(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); final boolean nightMode = !getMyApplication().getSettings().isLightContent(); @@ -52,6 +61,10 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container); LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout); + TextView titleTv = (TextView) mainView.findViewById(R.id.save_as_track_title); + titleTv.setText(isCoordInput ? R.string.coord_input_save_as_track : R.string.marker_save_as_track); + TextView descriptionTv = (TextView) mainView.findViewById(R.id.save_as_track_description); + descriptionTv.setText(isCoordInput ? getString(R.string.coord_input_save_as_track_descr, number) : getString(R.string.marker_save_as_track_descr)); int layoutRes; if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) { layoutRes = R.layout.markers_track_name_text_field_box; From 493b8c35de0f4f2bc5574011aafca1afc376d840 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 15 Jun 2018 18:22:50 +0300 Subject: [PATCH 03/19] change CoordinateInputAdapter constant and improve getting args in SaveAsTrackBottomSheetDialogFragment --- .../mapmarkers/SaveAsTrackBottomSheetDialogFragment.java | 5 +++-- .../plus/mapmarkers/adapters/CoordinateInputAdapter.java | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java index 1c8a143c82..8ce54e1fd5 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java @@ -49,8 +49,9 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { boolean isCoordInput = false; int number = 0; - if (getArguments() != null) { - number = getArguments().getInt(ADDED_MARKERS_NUMBER_KEY); + Bundle args = getArguments(); + if (args != null) { + number = args.getInt(ADDED_MARKERS_NUMBER_KEY); if (number != 0) isCoordInput = true; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index 268c574b77..4d9f5e1831 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -22,7 +22,7 @@ import java.util.List; public class CoordinateInputAdapter extends RecyclerView.Adapter { - public static final String ADAPTER_POSITION = "position"; + public static final String ADAPTER_POSITION = "adapter_position"; private OsmandApplication app; private List mapMarkers; From 57b220bdee5d048f58fc4159acaf5c6bd33e914b Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 15 Jun 2018 19:02:18 +0300 Subject: [PATCH 04/19] add button for hiding osmand keyboard --- .../res/layout/coordinate_input_keyboard.xml | 31 ++++++++++++++----- .../CoordinateInputDialogFragment.java | 12 +++++-- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_keyboard.xml b/OsmAnd/res/layout/coordinate_input_keyboard.xml index 9c60c34be8..4ed084b555 100644 --- a/OsmAnd/res/layout/coordinate_input_keyboard.xml +++ b/OsmAnd/res/layout/coordinate_input_keyboard.xml @@ -98,7 +98,7 @@ android:layout_height="match_parent"/> - + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index ef21dae289..9d6f47ec62 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -369,6 +369,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm case R.id.keyboard_item_next_field: switchEditText(focusedEditText.getId(), true); break; + case R.id.keyboard_item_hide: + changeOsmandKeyboardVisibility(false); + break; default: focusedEditText.setText(focusedEditText.getText().toString() + getItemObjectById(id)); focusedEditText.setSelection(focusedEditText.getText().length()); @@ -391,7 +394,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm R.id.keyboard_item_9, R.id.keyboard_item_clear, R.id.keyboard_item_next_field, - R.id.keyboard_item_backspace); + R.id.keyboard_item_backspace, + R.id.keyboard_item_hide); if (!isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); @@ -458,7 +462,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm for (@IdRes int id : itemsIds) { View itemView = keyboardView.findViewById(id); Object item = getItemObjectById(id); - final boolean controlItem = id == R.id.keyboard_item_next_field || id == R.id.keyboard_item_backspace; + final boolean controlItem = id == R.id.keyboard_item_next_field + || id == R.id.keyboard_item_backspace + || id == R.id.keyboard_item_hide; itemView.setBackgroundResource(controlItem ? controlItemBg : itemBg); itemView.setOnClickListener(listener); @@ -531,6 +537,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm return R.drawable.ic_keyboard_next_field; case R.id.keyboard_item_backspace: return R.drawable.ic_keyboard_backspace; + case R.id.keyboard_item_hide: + return R.drawable.ic_action_keyboard_hide; } return -1; } From 053ee106f5db4ae09a2c85fddd4034feb198f663 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 15 Jun 2018 19:13:24 +0300 Subject: [PATCH 05/19] rename ADAPTER_POSITION_KEY --- .../plus/mapmarkers/CoordinateInputActionsBottomSheet.java | 2 +- .../osmand/plus/mapmarkers/CoordinateInputDialogFragment.java | 2 +- .../osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java index 2746466fe6..ea8a4de9be 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputActionsBottomSheet.java @@ -26,7 +26,7 @@ public class CoordinateInputActionsBottomSheet extends MenuBottomSheetDialogFrag if (args == null) { return; } - final int position = args.getInt(CoordinateInputAdapter.ADAPTER_POSITION); + final int position = args.getInt(CoordinateInputAdapter.ADAPTER_POSITION_KEY); items.add(new TitleItem(getString(R.string.shared_string_actions))); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 9d6f47ec62..f41efc61ed 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -311,7 +311,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm return; } Bundle args = new Bundle(); - args.putInt(CoordinateInputAdapter.ADAPTER_POSITION, pos); + args.putInt(CoordinateInputAdapter.ADAPTER_POSITION_KEY, pos); CoordinateInputActionsBottomSheet fragment = new CoordinateInputActionsBottomSheet(); fragment.setUsedOnMap(false); fragment.setArguments(args); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index 4d9f5e1831..8df6bf3df7 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -22,7 +22,7 @@ import java.util.List; public class CoordinateInputAdapter extends RecyclerView.Adapter { - public static final String ADAPTER_POSITION = "adapter_position"; + public static final String ADAPTER_POSITION_KEY = "adapter_position_key"; private OsmandApplication app; private List mapMarkers; From f96525089d2e52e0e452a590a6e798318e25c0ea Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 18 Jun 2018 14:58:39 +0300 Subject: [PATCH 06/19] change bottom bar in coordinate input --- .../res/layout/coordinate_input_keyboard.xml | 6 +- .../coordinate_input_land_data_area.xml | 78 +++++++++-------- .../fragment_coordinate_input_dialog.xml | 82 ++++++++++------- .../CoordinateInputDialogFragment.java | 87 +++++-------------- .../adapters/CoordinateInputAdapter.java | 1 + 5 files changed, 121 insertions(+), 133 deletions(-) diff --git a/OsmAnd/res/layout/coordinate_input_keyboard.xml b/OsmAnd/res/layout/coordinate_input_keyboard.xml index 4ed084b555..167f6baf70 100644 --- a/OsmAnd/res/layout/coordinate_input_keyboard.xml +++ b/OsmAnd/res/layout/coordinate_input_keyboard.xml @@ -7,7 +7,11 @@ android:layout_height="wrap_content" android:orientation="vertical" tools:background="@color/keyboard_divider_dark"> - + + + + android:layout_height="@dimen/bottom_sheet_cancel_button_height" + android:background="?attr/wikivoyage_bottom_bar_bg_color"> - - - + android:paddingBottom="@dimen/context_menu_padding_margin_tiny" + android:paddingLeft="@dimen/bottom_sheet_content_margin" + android:paddingRight="@dimen/bottom_sheet_content_padding_small" + android:paddingTop="@dimen/context_menu_padding_margin_tiny" + android:text="@string/shared_string_cancel" + android:textColor="?attr/wikivoyage_active_color" + android:textSize="@dimen/text_button_text_size" + osmand:typeface="@string/font_roboto_medium" /> - + + + android:drawablePadding="@dimen/bottom_sheet_content_padding_small" + android:ellipsize="end" + android:gravity="center_vertical|end" + android:letterSpacing="@dimen/text_button_letter_spacing" + android:maxLines="1" + android:paddingBottom="@dimen/context_menu_padding_margin_tiny" + android:paddingLeft="@dimen/bottom_sheet_content_padding_small" + android:paddingRight="@dimen/bottom_sheet_content_margin" + android:paddingTop="@dimen/context_menu_padding_margin_tiny" + android:textColor="?attr/wikivoyage_active_color" + android:textSize="@dimen/text_button_text_size" + osmand:typeface="@string/font_roboto_medium" + tools:drawableRight="@drawable/ic_action_type_add" + tools:drawableTint="?attr/wikivoyage_active_color" + tools:ignore="UnusedAttribute" + tools:text="@string/shared_string_add" /> diff --git a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml index 33828faf27..6f5fad40f5 100644 --- a/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml +++ b/OsmAnd/res/layout/fragment_coordinate_input_dialog.xml @@ -95,8 +95,6 @@ android:layout_gravity="bottom" android:orientation="vertical"> - - + android:layout_height="@dimen/bottom_sheet_cancel_button_height" + android:background="?attr/wikivoyage_bottom_bar_bg_color"> - - - + android:drawablePadding="@dimen/bottom_sheet_content_padding_small" + android:ellipsize="end" + android:gravity="center_vertical" + android:letterSpacing="@dimen/text_button_letter_spacing" + android:maxLines="1" + android:paddingBottom="@dimen/context_menu_padding_margin_tiny" + android:paddingLeft="@dimen/bottom_sheet_content_margin" + android:paddingRight="@dimen/bottom_sheet_content_padding_small" + android:paddingTop="@dimen/context_menu_padding_margin_tiny" + android:text="@string/shared_string_cancel" + android:textColor="?attr/wikivoyage_active_color" + android:textSize="@dimen/text_button_text_size" + osmand:typeface="@string/font_roboto_medium" /> + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index f41efc61ed..fed5d116a1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -94,13 +94,11 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private View mainView; private final List editTexts = new ArrayList<>(); private CoordinateInputAdapter adapter; - private ImageView showHideKeyboardIcon; private Snackbar snackbar; private boolean lightTheme; private boolean orientationPortrait; - private boolean isSoftKeyboardShown; private boolean north = true; private boolean east = true; @@ -220,7 +218,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm lonBackspaceBtn.setImageDrawable(getActiveIcon(R.drawable.ic_action_clear_all_fields)); lonBackspaceBtn.setOnClickListener(backspaceOnClickListener); - showHideKeyboardIcon = (ImageView) mainView.findViewById(R.id.show_hide_keyboard_icon); } else { boolean rightHand = getMyApplication().getSettings().COORDS_INPUT_USE_RIGHT_SIDE.get(); LinearLayout handContainer = (LinearLayout) mainView.findViewById(R.id.hand_container); @@ -232,10 +229,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm ((FrameLayout) handContainer.findViewById(R.id.left_container)).addView(rightHand ? dataAreaView : keyboardAndListView, 0); ((FrameLayout) handContainer.findViewById(R.id.right_container)).addView(rightHand ? keyboardAndListView : dataAreaView, 0); - showHideKeyboardIcon = (ImageView) dataAreaView.findViewById(rightHand ? R.id.show_hide_keyboard_icon_right : R.id.show_hide_keyboard_icon_left); - showHideKeyboardIcon.setVisibility(View.VISIBLE); - dataAreaView.findViewById(rightHand ? R.id.show_hide_keyboard_icon_left : R.id.show_hide_keyboard_icon_right).setVisibility(View.GONE); - handContainer.findViewById(R.id.input_area_top_padding).setVisibility(View.VISIBLE); handContainer.findViewById(R.id.point_name_top_space).setVisibility(View.VISIBLE); handContainer.findViewById(R.id.right_shadow).setVisibility(rightHand ? View.VISIBLE : View.GONE); @@ -272,9 +265,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm new Handler().postDelayed(new Runnable() { @Override public void run() { - isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); - showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); } }, 200); } @@ -324,17 +315,25 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm setBackgroundColor(R.id.bottom_controls_container, lightTheme ? R.color.keyboard_item_control_light_bg : R.color.keyboard_item_control_dark_bg); TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button); - addButton.setBackgroundResource(lightTheme ? R.drawable.route_info_go_btn_bg_light : R.drawable.route_info_go_btn_bg_dark); - if (selectedMarker != null) { - addButton.setText(R.string.shared_string_save); - } + @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; + addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_add, colorId), null); + addButton.setText(R.string.shared_string_add); addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { addMapMarker(); } }); - + + TextView cancelButton = (TextView) mainView.findViewById(R.id.cancel_button); + cancelButton.setText(R.string.shared_string_cancel); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismissEditingMode(); + clearInputs(); + } + }); mainView.findViewById(R.id.keyboard_layout).setBackgroundResource(lightTheme ? R.drawable.bg_bottom_menu_light : R.drawable.bg_coordinate_input_keyboard_dark); @@ -400,52 +399,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (!isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); } - - showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); - showHideKeyboardIcon.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - boolean isCurrentlyVisible = isOsmandKeyboardCurrentlyVisible(); - if (isOsmandKeyboardOn() && !isSoftKeyboardShown) { - changeOsmandKeyboardVisibility(!isCurrentlyVisible); - } else { - final View focusedView = getDialog().getCurrentFocus(); - if (focusedView != null) { - if (isSoftKeyboardShown) { - isSoftKeyboardShown = false; - AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); - showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_show)); - } else { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - isSoftKeyboardShown = true; - AndroidUtils.showSoftKeyboard(focusedView); - showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); - } - }, 200); - } - changeEditTextSelections(); - } - } - } - }); - - mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - Rect r = new Rect(); - mainView.getWindowVisibleDisplayFrame(r); - int screenHeight = mainView.getRootView().getHeight(); - int keypadHeight = screenHeight - r.bottom; - if (keypadHeight > screenHeight * 0.15) { - isSoftKeyboardShown = true; - showHideKeyboardIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_keyboard_hide)); - } else { - isSoftKeyboardShown = false; - } - } - }); } private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) { @@ -555,7 +508,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm new Handler().postDelayed(new Runnable() { @Override public void run() { - isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); } }, 200); @@ -1003,9 +955,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } else { mainView.findViewById(R.id.keyboard_layout).setVisibility(visibility); } - showHideKeyboardIcon.setImageDrawable( - getActiveIcon(show ? R.drawable.ic_action_keyboard_hide : R.drawable.ic_action_keyboard_show) - ); } private void switchEditText(int currentId, boolean toNext) { @@ -1041,7 +990,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private void dismissEditingMode() { selectedMarker = null; - ((TextView) mainView.findViewById(R.id.add_marker_button)).setText(R.string.shared_string_add); + TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button); + addButton.setText(R.string.shared_string_add); + @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; + addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_add, colorId), null); } private void enterEditingMode(MapMarker marker) { @@ -1070,7 +1022,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm updateSideOfTheWorldBtn(mainView.findViewById(R.id.lon_side_of_the_world_btn), true); } ((EditText) mainView.findViewById(R.id.point_name_et)).setText(marker.getName(getContext())); - ((TextView) mainView.findViewById(R.id.add_marker_button)).setText(R.string.shared_string_save); + TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button); + addButton.setText(R.string.shared_string_apply); + @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; + addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_apply, colorId), null); } private void updateInputsDdm(boolean lat, DDM ddm, int accuracy) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index 8df6bf3df7..ace2c97021 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -69,6 +69,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter Date: Mon, 18 Jun 2018 15:29:32 +0300 Subject: [PATCH 07/19] add coordinate input to my places-tracks --- .../mapmarkers/CoordinateInputDialogFragment.java | 9 +++------ .../SaveAsTrackBottomSheetDialogFragment.java | 12 ++++++------ .../osmand/plus/myplaces/AvailableGPXFragment.java | 12 ++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index fed5d116a1..b1066eeb67 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -6,7 +6,6 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.res.ColorStateList; -import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; @@ -38,7 +37,6 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -60,7 +58,6 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener; @@ -1225,9 +1222,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (!compassUpdateAllowed) { return; } - final MapActivity mapActivity = (MapActivity) getActivity(); - if (mapActivity != null && adapter != null) { - mapActivity.getMyApplication().runInUIThread(new Runnable() { + final OsmandApplication app = getMyApplication(); + if (app != null && adapter != null) { + app.runInUIThread(new Runnable() { @Override public void run() { adapter.notifyDataSetChanged(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java index 8ce54e1fd5..c57e08f0eb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java @@ -21,9 +21,9 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; @@ -47,6 +47,7 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final OsmandApplication app = getMyApplication(); boolean isCoordInput = false; int number = 0; Bundle args = getArguments(); @@ -55,9 +56,8 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm if (number != 0) isCoordInput = true; } - MapActivity mapActivity = (MapActivity) getActivity(); portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - final boolean nightMode = !getMyApplication().getSettings().isLightContent(); + final boolean nightMode = !app.getSettings().isLightContent(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_save_as_track_bottom_sheet_dialog, container); @@ -81,16 +81,16 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm if (textBox instanceof TextInputLayout) { ((TextInputLayout) textBox).setHintTextAppearance(R.style.TextAppearance_App_DarkTextInputLayout); } else if (textBox instanceof OsmandTextFieldBoxes) { - ((OsmandTextFieldBoxes) textBox).setPrimaryColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); + ((OsmandTextFieldBoxes) textBox).setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark)); } } - final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); + final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); if (!dir.exists()) { dir.mkdirs(); } Date date = new Date(); - final String suggestedName = mapActivity.getString(R.string.markers) + "_" + DateFormat.format("yyyy-MM-dd", date).toString(); + final String suggestedName = app.getString(R.string.markers) + "_" + DateFormat.format("yyyy-MM-dd", date).toString(); String displayedName = suggestedName; File fout = new File(dir, suggestedName + GPX_SUFFIX); int ind = 1; diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 4a0a197dec..e14a42b2c5 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -77,6 +77,7 @@ import net.osmand.plus.download.ui.LocalIndexesFragment; import net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; +import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.util.Algorithms; @@ -474,6 +475,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { }); } else if (itemId == R.string.gpx_add_track) { addTrack(); + }else if (itemId == R.string.coordinate_input) { + openCoordinatesInput(); } return true; } @@ -481,6 +484,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.gpx_add_track, getActivity()) .setIcon(R.drawable.ic_action_plus) .setListener(listener).createItem()); + optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.coordinate_input, getActivity()) + .setIcon(R.drawable.ic_action_coordinates_longitude) + .setListener(listener).createItem()); optionsMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show_on_map, getActivity()) .setIcon(R.drawable.ic_show_on_map) .setListener(listener).createItem()); @@ -538,6 +544,12 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { ((FavoritesActivity) getActivity()).addTrack(); } + private void openCoordinatesInput() { + CoordinateInputDialogFragment fragment = new CoordinateInputDialogFragment(); + fragment.setRetainInstance(true); + fragment.show(getChildFragmentManager(), CoordinateInputDialogFragment.TAG); + } + public void showProgressBar() { ((FavoritesActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(true); } From ceab6bf6fcdd3d00bad2e89d4daa10a67903e298 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 18 Jun 2018 17:16:07 +0300 Subject: [PATCH 08/19] add quit dialog for saved gpx --- .../CoordinateInputDialogFragment.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index b1066eeb67..fc508c189c 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -95,6 +95,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean lightTheme; private boolean orientationPortrait; + private boolean isGpxSaved; private boolean north = true; private boolean east = true; @@ -116,6 +117,24 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm setStyle(STYLE_NO_FRAME, lightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme); } + private void quit() { + if (!mapMarkers.isEmpty() && !isGpxSaved) { + showQuitDialog(); + } else { + dismiss(); + } + } + + private void showQuitDialog() { + isGpxSaved = true; + SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); + Bundle args = new Bundle(); + args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size()); + fragment.setArguments(args); + fragment.setListener(createSaveAsTrackFragmentListener()); + fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG); + } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { @@ -126,8 +145,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); } else { - saveMarkers(); - super.onBackPressed(); + quit(); } } }; @@ -319,6 +337,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onClick(View view) { addMapMarker(); + isGpxSaved = false; } }); @@ -731,6 +750,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm switchEditText(textView.getId(), true); } else if (i == EditorInfo.IME_ACTION_DONE) { addMapMarker(); + isGpxSaved = false; } return false; } @@ -891,7 +911,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void saveGpx(final String fileName) { final String gpxPath = app.getMapMarkersHelper().generateGpxFromList(fileName, mapMarkers); - + isGpxSaved = true; snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_show, new View.OnClickListener() { @Override @@ -915,6 +935,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void removeItem(int position) { adapter.removeItem(position); + isGpxSaved = false; } @Override From c50941b5a97ae183f7949ad8f983ef721092c732 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 18 Jun 2018 17:27:37 +0300 Subject: [PATCH 09/19] fix saving markers with quit dialog --- .../osmand/plus/mapmarkers/CoordinateInputDialogFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index fc508c189c..e6167d5980 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -121,6 +121,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (!mapMarkers.isEmpty() && !isGpxSaved) { showQuitDialog(); } else { + saveMarkers(); dismiss(); } } From a3cd4a97d54caae5fb206010d31aa50848242c39 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 11:55:04 +0300 Subject: [PATCH 10/19] quit editing mode if selectedMarker id deleted --- .../CoordinateInputDialogFragment.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index e6167d5980..f7869f48dd 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -6,6 +6,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.content.res.ColorStateList; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; @@ -37,6 +38,7 @@ import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -97,6 +99,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean orientationPortrait; private boolean isGpxSaved; + private boolean isSoftKeyboardShown; private boolean north = true; private boolean east = true; @@ -416,6 +419,17 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (!isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) { changeOsmandKeyboardVisibility(false); } + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + Rect r = new Rect(); + mainView.getWindowVisibleDisplayFrame(r); + int screenHeight = mainView.getRootView().getHeight(); + int keypadHeight = screenHeight - r.bottom; + isSoftKeyboardShown = keypadHeight > screenHeight * 0.15; + } + }); } private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) { @@ -935,6 +949,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void removeItem(int position) { + if (selectedMarker == adapter.getItem(position)) { + dismissEditingMode(); + clearInputs(); + } adapter.removeItem(position); isGpxSaved = false; } From d124e239f38b367063b735246093c6531f058279 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 12:18:13 +0300 Subject: [PATCH 11/19] show keyboard after entering editing mode --- .../mapmarkers/CoordinateInputDialogFragment.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index f7869f48dd..cacc464666 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -1063,6 +1063,21 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm addButton.setText(R.string.shared_string_apply); @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_apply, colorId), null); + showKeyboard(); + } + + private void showKeyboard() { + if (isOsmandKeyboardOn()) { + if (!isOsmandKeyboardCurrentlyVisible()) { + editTexts.get(0).requestFocus(); + changeOsmandKeyboardVisibility(true); + } + } else { + if (!isSoftKeyboardShown) { + editTexts.get(0).requestFocus(); + AndroidUtils.softKeyboardDelayed(editTexts.get(0)); + } + } } private void updateInputsDdm(boolean lat, DDM ddm, int accuracy) { From 86d2d2736969b7d70fcfb4c9858acb20e42a9245 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 12:45:11 +0300 Subject: [PATCH 12/19] add Snackbar with Undo button for deleted items --- .../mapmarkers/CoordinateInputDialogFragment.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index cacc464666..9b55d0a612 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -948,13 +948,24 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm return new CoordinateInputActionsBottomSheet.CoordinateInputActionsListener() { @Override - public void removeItem(int position) { - if (selectedMarker == adapter.getItem(position)) { + public void removeItem(final int position) { + final MapMarker mapMarker = adapter.getItem(position); + if (selectedMarker == mapMarker) { dismissEditingMode(); clearInputs(); } adapter.removeItem(position); isGpxSaved = false; + snackbar = Snackbar.make(mainView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG) + .setAction(R.string.shared_string_undo, new View.OnClickListener() { + @Override + public void onClick(View view) { + mapMarkers.add(position, mapMarker); + adapter.notifyDataSetChanged(); + } + }); + AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark); + snackbar.show(); } @Override From b33923ca190c510e9a12f495675d3d588b1e5c91 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 14:19:15 +0300 Subject: [PATCH 13/19] add text for coordinate input toolbar and fix showKeyboard --- OsmAnd/res/values/strings.xml | 2 ++ .../CoordinateInputDialogFragment.java | 29 ++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 9be104d65b..557b7b3a21 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -10,6 +10,8 @@ - For wording and consistency, please note http://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience Thx - Hardy --> + Edit point + Add point Save as track You added %1$s points. Enter the name of the file and click save. Please send screenshoot of this notification to support@osmand.net diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 9b55d0a612..d8e047f706 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -186,13 +186,15 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (orientationPortrait) { backBtn.setImageDrawable(getActiveIcon(R.drawable.ic_arrow_back)); - ((TextView) mainView.findViewById(R.id.toolbar_text)) - .setTextColor(getResolvedColor(lightTheme ? R.color.color_black : R.color.color_white)); + TextView toolbar = (TextView) mainView.findViewById(R.id.toolbar_text); + toolbar.setTextColor(getResolvedColor(lightTheme ? R.color.color_black : R.color.color_white)); + toolbar.setText(R.string.coord_input_add_point); setBackgroundColor(R.id.app_bar, lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark); setBackgroundColor(mainView, lightTheme ? R.color.ctx_menu_info_view_bg_light : R.color.coordinate_input_markers_list_bg_dark); } else { - ((TextView) mainView.findViewById(R.id.toolbar_text)) - .setTextColor(getResolvedColor(lightTheme ? R.color.color_white : R.color.ctx_menu_title_color_dark)); + TextView toolbar = (TextView) mainView.findViewById(R.id.toolbar_text); + toolbar.setTextColor(getResolvedColor(lightTheme ? R.color.color_white : R.color.ctx_menu_title_color_dark)); + toolbar.setText(R.string.coord_input_add_point); setBackgroundColor(R.id.app_bar, lightTheme ? R.color.actionbar_light_color : R.color.route_info_bottom_view_bg_dark); } @@ -1042,6 +1044,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm addButton.setText(R.string.shared_string_add); @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; addButton.setCompoundDrawablesWithIntrinsicBounds(null, null, getColoredIcon(R.drawable.ic_action_type_add, colorId), null); + ((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_add_point); } private void enterEditingMode(MapMarker marker) { @@ -1070,6 +1073,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm updateSideOfTheWorldBtn(mainView.findViewById(R.id.lon_side_of_the_world_btn), true); } ((EditText) mainView.findViewById(R.id.point_name_et)).setText(marker.getName(getContext())); + ((TextView) mainView.findViewById(R.id.toolbar_text)).setText(R.string.coord_input_edit_point); TextView addButton = (TextView) mainView.findViewById(R.id.add_marker_button); addButton.setText(R.string.shared_string_apply); @ColorRes int colorId = lightTheme ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; @@ -1078,15 +1082,14 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void showKeyboard() { - if (isOsmandKeyboardOn()) { - if (!isOsmandKeyboardCurrentlyVisible()) { - editTexts.get(0).requestFocus(); - changeOsmandKeyboardVisibility(true); - } - } else { - if (!isSoftKeyboardShown) { - editTexts.get(0).requestFocus(); - AndroidUtils.softKeyboardDelayed(editTexts.get(0)); + for (EditText et : editTexts) { + if (et.getId() == R.id.lat_first_input_et) { + et.requestFocus(); + if (isOsmandKeyboardOn()) { + changeOsmandKeyboardVisibility(true); + } else { + AndroidUtils.softKeyboardDelayed(et); + } } } } From b0db8cd235c4c2fdeb7ef7c77c18b4b3226d2671 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 16:20:17 +0300 Subject: [PATCH 14/19] fix two keyboards in point_name_et --- .../CoordinateInputDialogFragment.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index d8e047f706..e3ae32f974 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -286,6 +286,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm new Handler().postDelayed(new Runnable() { @Override public void run() { + isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); } }, 200); @@ -691,6 +692,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm public boolean onTouch(View view, MotionEvent motionEvent) { if (isOsmandKeyboardOn()) { if (!isOsmandKeyboardCurrentlyVisible()) { + if (isSoftKeyboardShown) { + if (view.getId() != R.id.point_name_et) { + AndroidUtils.hideSoftKeyboard(getActivity(), view); + } else { + return false; + } + } changeOsmandKeyboardVisibility(true); } EditText editText = (EditText) view; @@ -820,8 +828,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm et.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { - if (!hasFocus && isOsmandKeyboardOn() && isOsmandKeyboardCurrentlyVisible()) { + if (!hasFocus && isOsmandKeyboardOn() && (isOsmandKeyboardCurrentlyVisible() || isSoftKeyboardShown)) { AndroidUtils.hideSoftKeyboard(getActivity(), v); + isSoftKeyboardShown = false; } } }); @@ -1082,16 +1091,20 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void showKeyboard() { + View focusedView = null; for (EditText et : editTexts) { if (et.getId() == R.id.lat_first_input_et) { et.requestFocus(); - if (isOsmandKeyboardOn()) { - changeOsmandKeyboardVisibility(true); - } else { - AndroidUtils.softKeyboardDelayed(et); - } + focusedView = getDialog().getCurrentFocus(); } } + if (isOsmandKeyboardOn()) { + if (!isOsmandKeyboardCurrentlyVisible()) { + changeOsmandKeyboardVisibility(true); + } + } else if (!isSoftKeyboardShown && focusedView != null) { + AndroidUtils.softKeyboardDelayed(focusedView); + } } private void updateInputsDdm(boolean lat, DDM ddm, int accuracy) { @@ -1246,7 +1259,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm et.clearFocus(); } if (editTexts.size() > 0) { - editTexts.get(0).requestFocus(); + showKeyboard(); } } From b43bac38c3242499a8623d906173f2d8590a7543 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 16:51:51 +0300 Subject: [PATCH 15/19] fix keyboards after changing keyboard option --- .../osmand/plus/mapmarkers/CoordinateInputDialogFragment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index e3ae32f974..924c23286e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -878,11 +878,13 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (focusedView != null) { if (useOsmandKeyboard) { AndroidUtils.hideSoftKeyboard(getActivity(), focusedView); + isSoftKeyboardShown = false; } else { new Handler().postDelayed(new Runnable() { @Override public void run() { AndroidUtils.showSoftKeyboard(focusedView); + isSoftKeyboardShown = true; } }, 200); } From 6f3dd8f9e87342a49b1f0e6ebd63344e146be15d Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 16:55:03 +0300 Subject: [PATCH 16/19] add isSoftKeyboardShown to onResume --- .../osmand/plus/mapmarkers/CoordinateInputDialogFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 924c23286e..8cce7971a1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -542,6 +542,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm new Handler().postDelayed(new Runnable() { @Override public void run() { + isSoftKeyboardShown = true; AndroidUtils.showSoftKeyboard(focusedView); } }, 200); From 5d344ab811355261720b903c4741ffac93b7473e Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 17:03:33 +0300 Subject: [PATCH 17/19] rename showQuitDialog and isGpxSaved --- .../CoordinateInputDialogFragment.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 8cce7971a1..4260abd1e8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -97,7 +97,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean lightTheme; private boolean orientationPortrait; - private boolean isGpxSaved; + private boolean isGpxSaveDialogShowed; private boolean isSoftKeyboardShown; private boolean north = true; @@ -121,16 +121,16 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void quit() { - if (!mapMarkers.isEmpty() && !isGpxSaved) { - showQuitDialog(); + if (!mapMarkers.isEmpty() && !isGpxSaveDialogShowed) { + showSaveDialog(); } else { saveMarkers(); dismiss(); } } - private void showQuitDialog() { - isGpxSaved = true; + private void showSaveDialog() { + isGpxSaveDialogShowed = true; SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); Bundle args = new Bundle(); args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size()); @@ -344,7 +344,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onClick(View view) { addMapMarker(); - isGpxSaved = false; + isGpxSaveDialogShowed = false; } }); @@ -776,7 +776,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm switchEditText(textView.getId(), true); } else if (i == EditorInfo.IME_ACTION_DONE) { addMapMarker(); - isGpxSaved = false; + isGpxSaveDialogShowed = false; } return false; } @@ -919,12 +919,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm if (mapMarkers.isEmpty()) { Toast.makeText(app, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show(); } else { - SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); - Bundle args = new Bundle(); - args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size()); - fragment.setArguments(args); - fragment.setListener(createSaveAsTrackFragmentListener()); - fragment.show(getChildFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG); + showSaveDialog(); } } @@ -940,7 +935,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void saveGpx(final String fileName) { final String gpxPath = app.getMapMarkersHelper().generateGpxFromList(fileName, mapMarkers); - isGpxSaved = true; + isGpxSaveDialogShowed = true; snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_show, new View.OnClickListener() { @Override @@ -969,7 +964,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm clearInputs(); } adapter.removeItem(position); - isGpxSaved = false; + isGpxSaveDialogShowed = false; snackbar = Snackbar.make(mainView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_undo, new View.OnClickListener() { @Override From d77ba13f8a8aff21ac02f0c8bb659548864f618a Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 17:46:48 +0300 Subject: [PATCH 18/19] add IndexConstants.MAP_MARKERS_INDEX_DIR --- OsmAnd-java/src/main/java/net/osmand/IndexConstants.java | 1 + OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java index a829bbc47f..a4f69ecbc7 100644 --- a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java @@ -50,6 +50,7 @@ public class IndexConstants { public static final String MAPS_PATH = ""; public static final String BACKUP_INDEX_DIR= "backup/"; public static final String GPX_INDEX_DIR = "tracks/"; + public static final String MAP_MARKERS_INDEX_DIR = "/map markers"; public static final String GPX_RECORDED_INDEX_DIR = GPX_INDEX_DIR + "rec/"; public static final String GPX_IMPORT_DIR = GPX_INDEX_DIR + "import/"; diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index f76351fecd..35a7dfb32c 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -995,7 +995,7 @@ public class MapMarkersHelper { } public String generateGpx(String fileName) { - final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); + final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR); if (!dir.exists()) { dir.mkdirs(); } @@ -1018,7 +1018,7 @@ public class MapMarkersHelper { } public String generateGpxFromList(String fileName, List mapMarkers) { - final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); + final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR); if (!dir.exists()) { dir.mkdirs(); } From 107a830d6e903935344362f3c56574124263de99 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 19 Jun 2018 18:01:10 +0300 Subject: [PATCH 19/19] rename isGpxSaveDialogShowed to hasUnsavedChanges --- .../mapmarkers/CoordinateInputDialogFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 4260abd1e8..8b9cc664f9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -97,7 +97,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean lightTheme; private boolean orientationPortrait; - private boolean isGpxSaveDialogShowed; + private boolean hasUnsavedChanges; private boolean isSoftKeyboardShown; private boolean north = true; @@ -121,7 +121,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void quit() { - if (!mapMarkers.isEmpty() && !isGpxSaveDialogShowed) { + if (!mapMarkers.isEmpty() && hasUnsavedChanges) { showSaveDialog(); } else { saveMarkers(); @@ -130,7 +130,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private void showSaveDialog() { - isGpxSaveDialogShowed = true; + hasUnsavedChanges = false; SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); Bundle args = new Bundle(); args.putInt(ADDED_MARKERS_NUMBER_KEY, mapMarkers.size()); @@ -344,7 +344,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onClick(View view) { addMapMarker(); - isGpxSaveDialogShowed = false; + hasUnsavedChanges = true; } }); @@ -776,7 +776,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm switchEditText(textView.getId(), true); } else if (i == EditorInfo.IME_ACTION_DONE) { addMapMarker(); - isGpxSaveDialogShowed = false; + hasUnsavedChanges = true; } return false; } @@ -935,7 +935,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void saveGpx(final String fileName) { final String gpxPath = app.getMapMarkersHelper().generateGpxFromList(fileName, mapMarkers); - isGpxSaveDialogShowed = true; + hasUnsavedChanges = false; snackbar = Snackbar.make(mainView, fileName + " " + getString(R.string.is_saved) + ".", Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_show, new View.OnClickListener() { @Override @@ -964,7 +964,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm clearInputs(); } adapter.removeItem(position); - isGpxSaveDialogShowed = false; + hasUnsavedChanges = true; snackbar = Snackbar.make(mainView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG) .setAction(R.string.shared_string_undo, new View.OnClickListener() { @Override