Search in sources :

Example 41 with GPXFile

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);
}
Also used : SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GpxSelectionHelper(net.osmand.plus.GpxSelectionHelper) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Example 42 with GPXFile

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;
}
Also used : GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) GPXUtilities(net.osmand.plus.GPXUtilities)

Example 43 with GPXFile

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();
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) Cursor(android.database.Cursor) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 44 with GPXFile

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;
            }
        }
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) GpxDisplayGroup(net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup) TrkSegment(net.osmand.plus.GPXUtilities.TrkSegment) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) Track(net.osmand.plus.GPXUtilities.Track) Location(net.osmand.Location)

Example 45 with GPXFile

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();
            }
        }
    });
}
Also used : ImageButton(android.widget.ImageButton) FileWriter(java.io.FileWriter) Intent(android.content.Intent) IconsCache(net.osmand.plus.IconsCache) IOException(java.io.IOException) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Uri(android.net.Uri) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Aggregations

GPXFile (net.osmand.plus.GPXUtilities.GPXFile)56 File (java.io.File)26 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)21 WptPt (net.osmand.plus.GPXUtilities.WptPt)16 OsmandApplication (net.osmand.plus.OsmandApplication)11 View (android.view.View)8 TextView (android.widget.TextView)8 Intent (android.content.Intent)7 ImageView (android.widget.ImageView)7 FavouritePoint (net.osmand.data.FavouritePoint)7 LatLon (net.osmand.data.LatLon)7 DialogInterface (android.content.DialogInterface)6 AlertDialog (android.support.v7.app.AlertDialog)6 ArrayList (java.util.ArrayList)6 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)6 OsmandSettings (net.osmand.plus.OsmandSettings)6 GpxDataItem (net.osmand.plus.GPXDatabase.GpxDataItem)5 Track (net.osmand.plus.GPXUtilities.Track)5 TrkSegment (net.osmand.plus.GPXUtilities.TrkSegment)5 AdapterView (android.widget.AdapterView)4