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);
}
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();
}
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;
}
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;
}
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);
}
}
Aggregations