Fix gpx selection dialog

This commit is contained in:
Alexey Kulish 2016-10-31 16:09:58 +03:00
parent 9c0130c82b
commit b2fefb4054
4 changed files with 39 additions and 35 deletions

View file

@ -550,10 +550,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
final Uri data = intent.getData(); final Uri data = intent.getData();
final String scheme = data.getScheme(); final String scheme = data.getScheme();
if ("file".equals(scheme)) { if ("file".equals(scheme)) {
gpxImportHelper.handleFileImport(data, new File(data.getPath()).getName()); gpxImportHelper.handleFileImport(data, new File(data.getPath()).getName(), true);
setIntent(null); setIntent(null);
} else if ("content".equals(scheme)) { } else if ("content".equals(scheme)) {
gpxImportHelper.handleContentImport(data); gpxImportHelper.handleContentImport(data, true);
setIntent(null); setIntent(null);
} else if ("google.navigation".equals(scheme) || "osmand.navigation".equals(scheme)) { } else if ("google.navigation".equals(scheme) || "osmand.navigation".equals(scheme)) {
parseNavigationIntent(data); parseNavigationIntent(data);

View file

@ -1075,8 +1075,9 @@ public class ConfigureMapMenu {
public static class GpxAppearanceAdapter extends ArrayAdapter<AppearanceListItem> { public static class GpxAppearanceAdapter extends ArrayAdapter<AppearanceListItem> {
private OsmandApplication app; private OsmandApplication app;
private int currentColor;
public GpxAppearanceAdapter(Context context) { public GpxAppearanceAdapter(Context context, String currentColorValue) {
super(context, R.layout.rendering_prop_menu_item); super(context, R.layout.rendering_prop_menu_item);
app = (OsmandApplication) getContext().getApplicationContext(); app = (OsmandApplication) getContext().getApplicationContext();
@ -1089,9 +1090,6 @@ public class ConfigureMapMenu {
} }
if (trackWidthProp != null) { if (trackWidthProp != null) {
final OsmandSettings.CommonPreference<String> pref
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_WIDTH_ATTR, "", AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_WIDTH_ATTR, "",
SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getDefaultValueDescription())); SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getDefaultValueDescription()));
add(item); add(item);
@ -1104,8 +1102,7 @@ public class ConfigureMapMenu {
item.setLastItem(true); item.setLastItem(true);
} }
if (trackColorProp != null) { if (trackColorProp != null) {
final OsmandSettings.CommonPreference<String> pref currentColor = parseTrackColor(renderer, currentColorValue);
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_COLOR_ATTR, "", AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_COLOR_ATTR, "",
SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getDefaultValueDescription()), SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getDefaultValueDescription()),
@ -1161,7 +1158,7 @@ public class ConfigureMapMenu {
iconId = R.drawable.ic_action_gpx_width_thin; iconId = R.drawable.ic_action_gpx_width_thin;
} }
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getIconsCache().getIcon(iconId, R.color.gpx_track_width_prop), null); app.getIconsCache().getPaintedIcon(iconId, currentColor), null);
} else { } else {
if (item.color == -1) { if (item.color == -1) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null, textView.setCompoundDrawablesWithIntrinsicBounds(null, null,

View file

@ -52,36 +52,36 @@ public class GpxImportHelper {
this.mapView = mapView; this.mapView = mapView;
} }
public void handleContentImport(final Uri contentUri) { public void handleContentImport(final Uri contentUri, final boolean useImportDir) {
final String name = getNameFromContentUri(contentUri); final String name = getNameFromContentUri(contentUri);
handleFileImport(contentUri, name); handleFileImport(contentUri, name, useImportDir);
} }
public boolean handleGpxImport(final Uri contentUri) { public boolean handleGpxImport(final Uri contentUri, final boolean useImportDir) {
final String name = getNameFromContentUri(contentUri); final String name = getNameFromContentUri(contentUri);
final boolean isOsmandSubdir = isSubDirectory(application.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath())); final boolean isOsmandSubdir = isSubDirectory(application.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath()));
if (!isOsmandSubdir && name.endsWith(GPX_SUFFIX)) { if (!isOsmandSubdir && name.endsWith(GPX_SUFFIX)) {
handleGpxImport(contentUri, name, true); handleGpxImport(contentUri, name, true, useImportDir);
return true; return true;
} }
return false; return false;
} }
public void handleFileImport(final Uri intentUri, final String fileName) { public void handleFileImport(final Uri intentUri, final String fileName, final boolean useImportDir) {
final boolean isFileIntent = "file".equals(intentUri.getScheme()); final boolean isFileIntent = "file".equals(intentUri.getScheme());
final boolean isOsmandSubdir = isSubDirectory(application.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath())); final boolean isOsmandSubdir = isSubDirectory(application.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
final boolean saveFile = !isFileIntent || !isOsmandSubdir; final boolean saveFile = !isFileIntent || !isOsmandSubdir;
if (fileName != null && fileName.endsWith(KML_SUFFIX)) { if (fileName != null && fileName.endsWith(KML_SUFFIX)) {
handleKmlImport(intentUri, fileName, saveFile); handleKmlImport(intentUri, fileName, saveFile, useImportDir);
//Issue 2275 //Issue 2275
// } else if (fileName != null && (fileName.contains("favourite")|| // } else if (fileName != null && (fileName.contains("favourite")||
// fileName.contains("favorite"))) { // fileName.contains("favorite"))) {
// handleFavouritesImport(intentUri, fileName, saveFile); // handleFavouritesImport(intentUri, fileName, saveFile);
} else { } else {
// handleGpxImport(intentUri, fileName, saveFile); // handleGpxImport(intentUri, fileName, saveFile);
handleFavouritesImport(intentUri, fileName, saveFile); handleFavouritesImport(intentUri, fileName, saveFile, useImportDir);
} }
} }
@ -99,7 +99,7 @@ public class GpxImportHelper {
return name; return name;
} }
private void handleGpxImport(final Uri gpxFile, final String fileName, final boolean save) { private void handleGpxImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir) {
new AsyncTask<Void, Void, GPXUtilities.GPXFile>() { new AsyncTask<Void, Void, GPXUtilities.GPXFile>() {
ProgressDialog progress = null; ProgressDialog progress = null;
@ -132,12 +132,12 @@ public class GpxImportHelper {
@Override @Override
protected void onPostExecute(GPXUtilities.GPXFile result) { protected void onPostExecute(GPXUtilities.GPXFile result) {
progress.dismiss(); progress.dismiss();
handleResult(result, fileName, save); handleResult(result, fileName, save, useImportDir);
} }
}.execute(); }.execute();
} }
private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save) { private void handleFavouritesImport(final Uri gpxFile, final String fileName, final boolean save, final boolean useImportDir) {
new AsyncTask<Void, Void, GPXUtilities.GPXFile>() { new AsyncTask<Void, Void, GPXUtilities.GPXFile>() {
ProgressDialog progress = null; ProgressDialog progress = null;
@ -170,7 +170,7 @@ public class GpxImportHelper {
@Override @Override
protected void onPostExecute(final GPXUtilities.GPXFile result) { protected void onPostExecute(final GPXUtilities.GPXFile result) {
progress.dismiss(); progress.dismiss();
importFavourites(result, fileName, save); importFavourites(result, fileName, save, useImportDir);
} }
}.execute(); }.execute();
} }
@ -207,7 +207,7 @@ public class GpxImportHelper {
}.execute(); }.execute();
} }
private void handleKmlImport(final Uri kmlFile, final String name, final boolean save) { private void handleKmlImport(final Uri kmlFile, final String name, final boolean save, final boolean useImportDir) {
new AsyncTask<Void, Void, GPXUtilities.GPXFile>() { new AsyncTask<Void, Void, GPXUtilities.GPXFile>() {
ProgressDialog progress = null; ProgressDialog progress = null;
@ -246,18 +246,18 @@ public class GpxImportHelper {
@Override @Override
protected void onPostExecute(GPXUtilities.GPXFile result) { protected void onPostExecute(GPXUtilities.GPXFile result) {
progress.dismiss(); progress.dismiss();
handleResult(result, name, save); handleResult(result, name, save, useImportDir);
} }
}.execute(); }.execute();
} }
private void handleResult(final GPXUtilities.GPXFile result, final String name, final boolean save) { private void handleResult(final GPXUtilities.GPXFile result, final String name, final boolean save, final boolean useImportDir) {
if (result != null) { if (result != null) {
if (result.warning != null) { if (result.warning != null) {
Toast.makeText(mapActivity, result.warning, Toast.LENGTH_LONG).show(); Toast.makeText(mapActivity, result.warning, Toast.LENGTH_LONG).show();
} else { } else {
if (save) { if (save) {
new SaveAsyncTask(result, name).execute(); new SaveAsyncTask(result, name, useImportDir).execute();
} else { } else {
showGpxOnMap(result); showGpxOnMap(result);
} }
@ -267,19 +267,23 @@ public class GpxImportHelper {
} }
} }
private String saveImport(final GPXUtilities.GPXFile gpxFile, final String fileName) { private String saveImport(final GPXUtilities.GPXFile gpxFile, final String fileName, final boolean useImportDir) {
final String warning; final String warning;
if (gpxFile.isEmpty() || fileName == null) { if (gpxFile.isEmpty() || fileName == null) {
warning = application.getString(R.string.error_reading_gpx); warning = application.getString(R.string.error_reading_gpx);
} else { } else {
final File importDir = application.getAppPath(IndexConstants.GPX_IMPORT_DIR); final File importDir;
if (useImportDir) {
importDir = application.getAppPath(IndexConstants.GPX_IMPORT_DIR);
} else {
importDir = application.getAppPath(IndexConstants.GPX_INDEX_DIR);
}
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
importDir.mkdirs(); importDir.mkdirs();
if (importDir.exists() && importDir.isDirectory() && importDir.canWrite()) { if (importDir.exists() && importDir.isDirectory() && importDir.canWrite()) {
final GPXUtilities.WptPt pt = gpxFile.findPointToShow(); final GPXUtilities.WptPt pt = gpxFile.findPointToShow();
final File toWrite = getFileToSave(fileName, importDir, pt); final File toWrite = getFileToSave(fileName, importDir, pt);
warning = GPXUtilities.writeGpxFile(toWrite, gpxFile, application); warning = GPXUtilities.writeGpxFile(toWrite, gpxFile, application);
if (warning == null) { if (warning == null) {
gpxFile.path = toWrite.getAbsolutePath(); gpxFile.path = toWrite.getAbsolutePath();
@ -308,15 +312,17 @@ public class GpxImportHelper {
private class SaveAsyncTask extends AsyncTask<Void, Void, String> { private class SaveAsyncTask extends AsyncTask<Void, Void, String> {
private final GPXUtilities.GPXFile result; private final GPXUtilities.GPXFile result;
private final String name; private final String name;
private final boolean useImportDir;
private SaveAsyncTask(GPXUtilities.GPXFile result, final String name) { private SaveAsyncTask(GPXUtilities.GPXFile result, final String name, boolean useImportDir) {
this.result = result; this.result = result;
this.name = name; this.name = name;
this.useImportDir = useImportDir;
} }
@Override @Override
protected String doInBackground(Void... nothing) { protected String doInBackground(Void... nothing) {
return saveImport(result, name); return saveImport(result, name, useImportDir);
} }
@Override @Override
@ -341,9 +347,9 @@ public class GpxImportHelper {
} }
} }
private void importFavourites(final GPXUtilities.GPXFile gpxFile, final String fileName, final boolean save) { private void importFavourites(final GPXUtilities.GPXFile gpxFile, final String fileName, final boolean save, final boolean useImportDir) {
if(gpxFile == null || gpxFile.points == null || gpxFile.points.size() == 0) { if(gpxFile == null || gpxFile.points == null || gpxFile.points.size() == 0) {
handleResult(gpxFile, fileName, save); handleResult(gpxFile, fileName, save, useImportDir);
return; return;
} }
final DialogInterface.OnClickListener importFavouritesListener = new DialogInterface.OnClickListener() { final DialogInterface.OnClickListener importFavouritesListener = new DialogInterface.OnClickListener() {
@ -354,7 +360,7 @@ public class GpxImportHelper {
importFavoritesImpl(gpxFile); importFavoritesImpl(gpxFile);
break; break;
case DialogInterface.BUTTON_NEGATIVE: case DialogInterface.BUTTON_NEGATIVE:
handleResult(gpxFile, fileName, save); handleResult(gpxFile, fileName, save, useImportDir);
break; break;
} }
} }

View file

@ -429,7 +429,7 @@ public class GpxUiHelper {
return v; return v;
} }
tv.setText(item.getTitle()); tv.setText(item.getTitle().replace("/", ""));
GPXInfo info = list.get(position); GPXInfo info = list.get(position);
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (info.getLastModified() > 0) { if (info.getLastModified() > 0) {
@ -526,7 +526,8 @@ public class GpxUiHelper {
popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP); popup.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
popup.setVerticalOffset(AndroidUtils.dpToPx(activity, -48f)); popup.setVerticalOffset(AndroidUtils.dpToPx(activity, -48f));
popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f)); popup.setHorizontalOffset(AndroidUtils.dpToPx(activity, -6f));
final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(activity); final GpxAppearanceAdapter gpxApprAdapter = new GpxAppearanceAdapter(activity,
gpxAppearanceParams.containsKey(CURRENT_TRACK_COLOR_ATTR) ? gpxAppearanceParams.get(CURRENT_TRACK_COLOR_ATTR) : prefColor.get());
popup.setAdapter(gpxApprAdapter); popup.setAdapter(gpxApprAdapter);
popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@ -676,7 +677,7 @@ public class GpxUiHelper {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
if (resultData != null) { if (resultData != null) {
Uri uri = resultData.getData(); Uri uri = resultData.getData();
if (mapActivity.getGpxImportHelper().handleGpxImport(uri)) { if (mapActivity.getGpxImportHelper().handleGpxImport(uri, false)) {
dialog.dismiss(); dialog.dismiss();
} }
} }