Search in sources :

Example 16 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class GpxUiHelper method selectGPXFiles.

public static AlertDialog selectGPXFiles(List<String> selectedGpxList, final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject) {
    OsmandApplication app = (OsmandApplication) activity.getApplication();
    final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    final List<GPXInfo> allGpxList = getSortedGPXFilesInfo(dir, selectedGpxList, false);
    if (allGpxList.isEmpty()) {
        Toast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
    }
    allGpxList.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0));
    final ContextMenuAdapter adapter = createGpxContextMenuAdapter(allGpxList, selectedGpxList, true);
    return createDialog(activity, true, true, true, callbackWithObject, allGpxList, adapter);
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 17 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class GpxUiHelper method loadGPXFileInDifferentThread.

private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject, final File dir, final GPXFile currentFile, final String... filename) {
    final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""), activity.getString(R.string.loading_data));
    new Thread(new Runnable() {

        @Override
        public void run() {
            final GPXFile[] result = new GPXFile[filename.length + (currentFile == null ? 0 : 1)];
            int k = 0;
            String w = "";
            if (currentFile != null) {
                result[k++] = currentFile;
            }
            for (String fname : filename) {
                final File f = new File(dir, fname);
                GPXFile res = GPXUtilities.loadGPXFile(activity.getApplication(), f);
                if (res.warning != null && res.warning.length() > 0) {
                    w += res.warning + "\n";
                }
                result[k++] = res;
            }
            dlg.dismiss();
            final String warn = w;
            activity.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (warn.length() > 0) {
                        Toast.makeText(activity, warn, Toast.LENGTH_LONG).show();
                    } else {
                        callbackWithObject.processResult(result);
                    }
                }
            });
        }
    }, "Loading gpx").start();
}
Also used : SpannableString(android.text.SpannableString) ProgressDialog(android.app.ProgressDialog) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SuppressLint(android.annotation.SuppressLint)

Example 18 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class GpxUiHelper method selectGPXFile.

public static AlertDialog selectGPXFile(final Activity activity, final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile[]> callbackWithObject) {
    OsmandApplication app = (OsmandApplication) activity.getApplication();
    final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    final List<GPXInfo> list = getSortedGPXFilesInfo(dir, null, false);
    if (list.isEmpty()) {
        Toast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
    }
    if (!list.isEmpty() || showCurrentGpx) {
        if (showCurrentGpx) {
            list.add(0, new GPXInfo(activity.getString(R.string.show_current_gpx_title), 0, 0));
        }
        final ContextMenuAdapter adapter = createGpxContextMenuAdapter(list, null, showCurrentGpx);
        return createDialog(activity, showCurrentGpx, multipleChoice, false, callbackWithObject, list, adapter);
    }
    return null;
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmandApplication(net.osmand.plus.OsmandApplication) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 19 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class WptPtEditorFragment method createSelectCategoryDialog.

@Override
protected DialogFragment createSelectCategoryDialog() {
    SelectCategoryDialogFragment selectCategoryDialogFragment = SelectCategoryDialogFragment.createInstance(getEditor().getFragmentTag());
    GPXFile gpx = editor.getGpxFile();
    if (gpx != null) {
        selectCategoryDialogFragment.setGpxFile(gpx);
    }
    return selectCategoryDialogFragment;
}
Also used : GPXFile(net.osmand.plus.GPXUtilities.GPXFile)

Example 20 with GPXFile

use of net.osmand.plus.GPXUtilities.GPXFile in project Osmand by osmandapp.

the class OsmandAidlApi method finishGpxImport.

private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
    int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
    if (!destinationExists) {
        GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
        gpxDataItem.setApiImported(true);
        app.getGpxDatabase().add(gpxDataItem);
    } else {
        GpxDataItem item = app.getGpxDatabase().getItem(destination);
        if (item != null) {
            app.getGpxDatabase().updateColor(item, col);
        }
    }
    final GpxSelectionHelper helper = app.getSelectedGpxHelper();
    final SelectedGpxFile selectedGpx = helper.getSelectedFileByName(destination.getName());
    if (selectedGpx != null) {
        if (show) {
            new AsyncTask<File, Void, GPXFile>() {

                @Override
                protected GPXFile doInBackground(File... files) {
                    return GPXUtilities.loadGPXFile(app, files[0]);
                }

                @Override
                protected void onPostExecute(GPXFile gpx) {
                    if (gpx.warning == null) {
                        selectedGpx.setGpxFile(gpx);
                        refreshMap();
                    }
                }
            }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
        } else {
            helper.selectGpxFile(selectedGpx.getGpxFile(), false, false);
            refreshMap();
        }
    } else if (show) {
        new AsyncTask<File, Void, GPXFile>() {

            @Override
            protected GPXFile doInBackground(File... files) {
                return GPXUtilities.loadGPXFile(app, files[0]);
            }

            @Override
            protected void onPostExecute(GPXFile gpx) {
                if (gpx.warning == null) {
                    helper.selectGpxFile(gpx, true, false);
                    refreshMap();
                }
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, destination);
    }
}
Also used : SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) GpxDataItem(net.osmand.plus.GPXDatabase.GpxDataItem) AsyncTask(android.os.AsyncTask) GpxSelectionHelper(net.osmand.plus.GpxSelectionHelper) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) ASelectedGpxFile(net.osmand.aidl.gpx.ASelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) FavouritePoint(net.osmand.data.FavouritePoint) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint)

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