diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 04b4b8035a..fdfd8c2bde 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -40,7 +40,7 @@ + tools:overrideLibrary="com.getkeepsafe.taptargetview, studio.carbonylgroup.textfieldboxes"/> diff --git a/OsmAnd/no_translate.xml b/OsmAnd/no_translate.xml index 1e2c77f356..a55605f15a 100644 --- a/OsmAnd/no_translate.xml +++ b/OsmAnd/no_translate.xml @@ -32,4 +32,5 @@ Reopen items modified OsmAnd Unlimited + Markers 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 new file mode 100644 index 0000000000..099da8e742 --- /dev/null +++ b/OsmAnd/res/layout/fragment_marker_save_as_track_bottom_sheet_dialog.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/markers_track_name_edit_text.xml b/OsmAnd/res/layout/markers_track_name_edit_text.xml new file mode 100644 index 0000000000..336170833b --- /dev/null +++ b/OsmAnd/res/layout/markers_track_name_edit_text.xml @@ -0,0 +1,22 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/markers_track_name_text_field_box.xml b/OsmAnd/res/layout/markers_track_name_text_field_box.xml new file mode 100644 index 0000000000..1679a91832 --- /dev/null +++ b/OsmAnd/res/layout/markers_track_name_text_field_box.xml @@ -0,0 +1,23 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c6c8e60c41..e47caa629b 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 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 --> + is saved + OsmAnd will save all your markers to a separate file, you can enter filename: + Save as track Move to history Group will be removed after restart Show guide line diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 3d5d717eef..c5e44fbe61 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -829,13 +829,11 @@ public class MapMarkersHelper { } } - public void generateGpx() { + public String generateGpx(String fileName) { final File dir = ctx.getAppPath(IndexConstants.GPX_INDEX_DIR + "/map markers"); if (!dir.exists()) { dir.mkdirs(); } - Date date = new Date(); - String fileName = DateFormat.format("yyyy-MM-dd", date).toString() + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(date); File fout = new File(dir, fileName + ".gpx"); int ind = 1; while (fout.exists()) { @@ -851,6 +849,7 @@ public class MapMarkersHelper { file.addPoint(wpt); } GPXUtilities.writeGpxFile(fout, file, ctx); + return fout.getAbsolutePath(); } private void removeHistoryMarkersFromGroups() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 25b3ea47c1..6abc17b432 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapmarkers; +import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -16,6 +17,8 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import net.osmand.IndexConstants; +import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.LockableViewPager; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.OsmandApplication; @@ -23,11 +26,14 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener; +import net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener; import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -92,6 +98,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm if (orderByFragment != null) { ((OrderByBottomSheetDialogFragment) orderByFragment).setListener(createOrderByFragmentListener()); } + Fragment saveAsTrackFragment = fragmentManager.findFragmentByTag(SaveAsTrackBottomSheetDialogFragment.TAG); + if (saveAsTrackFragment != null) { + ((SaveAsTrackBottomSheetDialogFragment) saveAsTrackFragment).setListener(createSaveAsTrackFragmentListener()); + } View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); @@ -201,7 +211,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void saveAsNewTrackOnClick() { - mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(); + SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); + fragment.setListener(createSaveAsTrackFragmentListener()); + fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG); } @Override @@ -240,6 +252,33 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm }; } + private MarkerSaveAsTrackFragmentListener createSaveAsTrackFragmentListener() { + return new MarkerSaveAsTrackFragmentListener() { + + final MapActivity mapActivity = getMapActivity(); + + @Override + public void saveGpx(final String fileName) { + final String gpxPath = mapActivity.getMyApplication().getMapMarkersHelper().generateGpx(fileName); + snackbar = Snackbar.make(viewPager, 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(mapActivity, 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); + } + }); + View snackBarView = snackbar.getView(); + TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action); + tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); + snackbar.show(); + } + }; + } + private OrderByFragmentListener createOrderByFragmentListener() { return new OrderByFragmentListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java new file mode 100644 index 0000000000..f625f5b7e5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SaveAsTrackBottomSheetDialogFragment.java @@ -0,0 +1,160 @@ +package net.osmand.plus.mapmarkers; + +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.text.format.DateFormat; +import android.util.Log; +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.IndexConstants; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import studio.carbonylgroup.textfieldboxes.ExtendedEditText; + +import static net.osmand.plus.helpers.GpxImportHelper.GPX_SUFFIX; + +public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment { + + public final static String TAG = "SaveAsTrackBottomSheetDialogFragment"; + + private boolean portrait; + private MarkerSaveAsTrackFragmentListener listener; + + public void setListener(MarkerSaveAsTrackFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + MapActivity mapActivity = (MapActivity) getActivity(); + portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean nightMode = !getMyApplication().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); + LinearLayout contentLayout = (LinearLayout) mainView.findViewById(R.id.content_linear_layout); + int layoutRes; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + layoutRes = R.layout.markers_track_name_text_field_box; + } else { + layoutRes = R.layout.markers_track_name_edit_text; + } + contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 2); + if (portrait) { + AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } + + final File dir = mapActivity.getMyApplication().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("dd_MM_yyyy", date).toString(); + String displayedName = suggestedName; + File fout = new File(dir, suggestedName + GPX_SUFFIX); + int ind = 1; + while (fout.exists()) { + displayedName = suggestedName + "_" + (++ind); + fout = new File(dir, displayedName + GPX_SUFFIX); + } + final EditText nameEditText = (EditText) mainView.findViewById(R.id.name_edit_text); + nameEditText.setText(displayedName); + nameEditText.requestFocus(); + + mainView.findViewById(R.id.save_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.saveGpx(nameEditText.getText().toString()); + } + 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.marker_save_as_track_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, false, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(getActivity(), mainView, false, + 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 (!portrait) { + 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); + } + } + + interface MarkerSaveAsTrackFragmentListener { + void saveGpx(String fileName); + } +}