use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class AddTracksGroupBottomSheetDialogFragment method createMapMarkersSyncGroup.
private MapMarkersGroup createMapMarkersSyncGroup(OsmandApplication app, GpxDataItem gpxDataItem) {
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
File gpx = gpxDataItem.getFile();
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
if (selectedGpxFile == null) {
GPXFile res = GPXUtilities.loadGPXFile(app, gpx);
gpxSelectionHelper.selectGpxFile(res, true, false);
}
return getMyApplication().getMapMarkersHelper().getOrCreateGroup(gpx);
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class ImportHelper method saveImport.
private String saveImport(final GPXFile gpxFile, final String fileName, final boolean useImportDir) {
final String warning;
if (gpxFile.isEmpty() || fileName == null) {
warning = app.getString(R.string.error_reading_gpx);
} else {
final File importDir;
if (useImportDir) {
importDir = app.getAppPath(IndexConstants.GPX_IMPORT_DIR);
} else {
importDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
}
// noinspection ResultOfMethodCallIgnored
importDir.mkdirs();
if (importDir.exists() && importDir.isDirectory() && importDir.canWrite()) {
final GPXUtilities.WptPt pt = gpxFile.findPointToShow();
final File toWrite = getFileToSave(fileName, importDir, pt);
warning = GPXUtilities.writeGpxFile(toWrite, gpxFile, app);
if (warning == null) {
gpxFile.path = toWrite.getAbsolutePath();
}
} else {
warning = app.getString(R.string.sd_dir_not_accessible);
}
}
return warning;
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class SavingTrackHelper method collectDBPoints.
private void collectDBPoints(SQLiteDatabase db, Map<String, GPXFile> dataTracks) {
Cursor query = db.rawQuery(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
"SELECT " + POINT_COL_LAT + "," + POINT_COL_LON + "," + POINT_COL_DATE + "," + POINT_COL_DESCRIPTION + "," + POINT_COL_NAME + "," + POINT_COL_CATEGORY + "," + POINT_COL_COLOR + " FROM " + POINT_NAME + " ORDER BY " + POINT_COL_DATE + " ASC", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
null);
if (query.moveToFirst()) {
do {
WptPt pt = new WptPt();
pt.lat = query.getDouble(0);
pt.lon = query.getDouble(1);
long time = query.getLong(2);
pt.time = time;
pt.desc = query.getString(3);
pt.name = query.getString(4);
pt.category = query.getString(5);
int color = query.getInt(6);
if (color != 0) {
pt.setColor(color);
}
// check if name is extension (needed for audio/video plugin & josm integration)
if (pt.name != null && pt.name.length() > 4 && pt.name.charAt(pt.name.length() - 4) == '.') {
pt.link = pt.name;
}
// $NON-NLS-1$
String date = DateFormat.format("yyyy-MM-dd", time).toString();
GPXFile gpx;
if (dataTracks.containsKey(date)) {
gpx = dataTracks.get(date);
} else {
gpx = new GPXFile();
dataTracks.put(date, gpx);
}
ctx.getSelectedGpxHelper().addPoint(pt, gpx);
} while (query.moveToNext());
}
query.close();
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class ShowRouteInfoDialogFragment method makeGpx.
private void makeGpx() {
double lastHeight = HEIGHT_UNDEFINED;
gpx = new GPXFile();
List<Location> locations = helper.getRoute().getRouteLocations();
if (locations != null) {
Track track = new Track();
TrkSegment seg = new TrkSegment();
for (Location l : locations) {
WptPt point = new WptPt();
point.lat = l.getLatitude();
point.lon = l.getLongitude();
if (l.hasAltitude()) {
if (!hasHeights) {
hasHeights = true;
}
float h = (float) l.getAltitude();
point.ele = h;
if (lastHeight == HEIGHT_UNDEFINED && seg.points.size() > 0) {
for (WptPt pt : seg.points) {
if (Double.isNaN(pt.ele)) {
pt.ele = h;
}
}
}
lastHeight = h;
}
seg.points.add(point);
}
track.segments.add(seg);
gpx.tracks.add(track);
String groupName = getMyApplication().getString(R.string.current_route);
GpxDisplayGroup group = getMyApplication().getSelectedGpxHelper().buildGpxDisplayGroup(gpx, 0, groupName);
if (group != null && group.getModifiableList().size() > 0) {
gpxItem = group.getModifiableList().get(0);
if (gpxItem != null) {
gpxItem.route = true;
}
}
}
}
use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.
the class ShowRouteInfoDialogFragment method buildMenuButtons.
private void buildMenuButtons() {
IconsCache iconsCache = getMyApplication().getIconsCache();
ImageButton printRoute = (ImageButton) view.findViewById(R.id.print_route);
printRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gprint_dark));
printRoute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
print();
}
});
ImageButton saveRoute = (ImageButton) view.findViewById(R.id.save_as_gpx);
saveRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gsave_dark));
saveRoute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivityActions.createSaveDirections(getActivity(), helper).show();
}
});
ImageButton shareRoute = (ImageButton) view.findViewById(R.id.share_as_gpx);
shareRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark));
shareRoute.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final GPXFile gpx = helper.generateGPXFileWithRoute();
final Uri fileUri = Uri.fromFile(new File(gpx.path));
File dir = new File(getActivity().getCacheDir(), "share");
if (!dir.exists()) {
dir.mkdir();
}
File dst = new File(dir, "route.gpx");
try {
FileWriter fw = new FileWriter(dst);
GPXUtilities.writeGpx(fw, gpx, getMyApplication());
fw.close();
final Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtml(adapter, helper.getGeneralRouteInformation()).toString()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_route_subject));
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(), getActivity().getPackageName() + ".fileprovider", dst));
sendIntent.setType("text/plain");
startActivity(sendIntent);
} catch (IOException e) {
// Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(),
// Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
});
}
Aggregations