add save as track function to coordinate input
This commit is contained in:
parent
0c2056f7c5
commit
b42f00554a
6 changed files with 110 additions and 0 deletions
|
@ -32,6 +32,7 @@
|
|||
osmand:typeface="@string/font_roboto_medium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/save_as_track_description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_descr_height"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
|
|
|
@ -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
|
||||
-->
|
||||
<string name="coord_input_save_as_track">Save as track</string>
|
||||
<string name="coord_input_save_as_track_descr">You added %1$s points. Enter the name of the file and click save.</string>
|
||||
<string name="error_notification_desc">Please send screenshoot of this notification to support@osmand.net</string>
|
||||
<string name="quick_action_edit_actions">Edit actions</string>
|
||||
<string name="get_osmand_live">Get OsmAnd Live to unlock all features: Daily map updates with unlimited downloads, all paid and free plugins, Wikipedia, Wikivoyage and much more.</string>
|
||||
|
|
|
@ -1016,6 +1016,29 @@ public class MapMarkersHelper {
|
|||
GPXUtilities.writeGpxFile(fout, file, ctx);
|
||||
return fout.getAbsolutePath();
|
||||
}
|
||||
|
||||
public String generateGpxFromList(String fileName, List<MapMarker> 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();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MapMarker> mapMarkers = new ArrayList<>();
|
||||
private MapMarker selectedMarker;
|
||||
|
@ -91,6 +95,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
private final List<EditTextEx> 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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue