Fix small issues and add possibility for multiple gpx files

This commit is contained in:
Victor Shcherb 2013-02-06 14:21:40 +01:00
parent a352dbe0cf
commit c44d2470c8
5 changed files with 104 additions and 63 deletions

View file

@ -78,7 +78,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private static final int SELECT_ALL_ID = 1; private static final int SELECT_ALL_ID = 1;
private static final int DESELECT_ALL_ID = 2; private static final int DESELECT_ALL_ID = 2;
private static final int FILTER_EXISTING_REGIONS = 3; private static final int FILTER_EXISTING_REGIONS = 3;
private static final int DOWNLOAD_FILES_TYPE = 4;
/** dialogs **/ /** dialogs **/
public static final int DIALOG_MAP_VERSION_UPDATE = 0; public static final int DIALOG_MAP_VERSION_UPDATE = 0;
@ -237,7 +236,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
menu.add(0, SELECT_ALL_ID, 0, R.string.select_all); menu.add(0, SELECT_ALL_ID, 0, R.string.select_all);
menu.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all); menu.add(0, DESELECT_ALL_ID, 0, R.string.deselect_all);
menu.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes); menu.add(0, FILTER_EXISTING_REGIONS, 0, R.string.filter_existing_indexes);
menu.add(0, DOWNLOAD_FILES_TYPE, 0, R.string.download_select_map_types);
} }
return true; return true;
} }
@ -294,8 +292,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} }
listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getClientContext(), filtered)); listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getClientContext(), filtered));
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
} else if (item.getItemId() == DOWNLOAD_FILES_TYPE) {
selectDownloadType();
} else if(item.getItemId() == DESELECT_ALL_ID){ } else if(item.getItemId() == DESELECT_ALL_ID){
entriesToDownload.clear(); entriesToDownload.clear();
listAdapter.notifyDataSetInvalidated(); listAdapter.notifyDataSetInvalidated();
@ -308,7 +304,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
} }
private void selectDownloadType() { public void selectDownloadType() {
Builder bld = new AlertDialog.Builder(this); Builder bld = new AlertDialog.Builder(this);
final DownloadActivityType[] items = getDownloadTypes(); final DownloadActivityType[] items = getDownloadTypes();
bld.setItems(toString(items), new DialogInterface.OnClickListener() { bld.setItems(toString(items), new DialogInterface.OnClickListener() {

View file

@ -672,7 +672,7 @@ public class MapActivityActions implements DialogProvider {
public void navigateUsingGPX(final ApplicationMode appMode) { public void navigateUsingGPX(final ApplicationMode appMode) {
final LatLon endForRouting = mapActivity.getPointToNavigate(); final LatLon endForRouting = mapActivity.getPointToNavigate();
final MapActivityLayers mapLayers = mapActivity.getMapLayers(); final MapActivityLayers mapLayers = mapActivity.getMapLayers();
mapLayers.selectGPXFileLayer(new CallbackWithObject<GPXFile>() { mapLayers.selectGPXFileLayer(false, false, false, new CallbackWithObject<GPXFile>() {
@Override @Override
public boolean processResult(final GPXFile result) { public boolean processResult(final GPXFile result) {
@ -726,7 +726,7 @@ public class MapActivityActions implements DialogProvider {
builder.show(); builder.show();
return true; return true;
} }
}, false, false); });
} }
private ApplicationMode getAppMode(ToggleButton[] buttons, OsmandSettings settings){ private ApplicationMode getAppMode(ToggleButton[] buttons, OsmandSettings settings){

View file

@ -348,7 +348,7 @@ public class MapActivityLayers {
public void showGPXFileLayer(final OsmandMapTileView mapView){ public void showGPXFileLayer(final OsmandMapTileView mapView){
final OsmandSettings settings = getApplication().getSettings(); final OsmandSettings settings = getApplication().getSettings();
selectGPXFileLayer(new CallbackWithObject<GPXFile>() { selectGPXFileLayer(true, true, true, new CallbackWithObject<GPXFile>() {
@Override @Override
public boolean processResult(GPXFile result) { public boolean processResult(GPXFile result) {
GPXFile toShow = result; GPXFile toShow = result;
@ -375,13 +375,75 @@ public class MapActivityLayers {
mapView.refreshMap(); mapView.refreshMap();
return true; return true;
} }
}, true, true); });
} }
public void selectGPXFileLayer(final CallbackWithObject<GPXFile> callbackWithObject, final boolean convertCloudmade, public void selectGPXFileLayer(final boolean convertCloudmade,
final boolean showCurrentGpx) { final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile> callbackWithObject) {
final List<String> list = new ArrayList<String>();
final File dir = getApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); final File dir = getApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
final List<String> list = getSortedGPXFilenames(dir);
if(list.isEmpty()){
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
}
if(!list.isEmpty() || showCurrentGpx){
Builder builder = new AlertDialog.Builder(activity);
if(showCurrentGpx){
list.add(0, getString(R.string.show_current_gpx_title));
}
String[] items = list.toArray(new String[list.size()]);
if (multipleChoice) {
final boolean[] selected = new boolean[items.length];
builder.setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
selected[which] = isChecked;
}
});
builder.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (showCurrentGpx && selected[0]) {
callbackWithObject.processResult(null);
} else {
List<String> s = new ArrayList<String>();
for (int i = 0; i < selected.length; i++) {
if (selected[i]) {
s.add(list.get(i));
}
}
loadGPXFileInDifferentThread(callbackWithObject, convertCloudmade, dir, s.toArray(new String[s.size()]));
}
}
});
} else {
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (showCurrentGpx && which == 0) {
callbackWithObject.processResult(null);
} else {
loadGPXFileInDifferentThread(callbackWithObject, convertCloudmade, dir, list.get(which));
}
}
});
}
AlertDialog dlg = builder.show();
try {
dlg.getListView().setFastScrollEnabled(true);
} catch(Exception e) {
// java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
// Unknown reason but on some devices fail
}
}
}
private List<String> getSortedGPXFilenames(File dir) {
final List<String> list = new ArrayList<String>();
if (dir != null && dir.canRead()) { if (dir != null && dir.canRead()) {
File[] files = dir.listFiles(); File[] files = dir.listFiles();
if (files != null) { if (files != null) {
@ -405,56 +467,40 @@ public class MapActivityLayers {
} }
} }
} }
return list;
}
if(list.isEmpty()){ private void loadGPXFileInDifferentThread(final CallbackWithObject<GPXFile> callbackWithObject,
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show(); final boolean convertCloudmade, final File dir, final String... filename) {
} final ProgressDialog dlg = ProgressDialog.show(activity, getString(R.string.loading),
if(!list.isEmpty() || showCurrentGpx){ getString(R.string.loading_data));
Builder builder = new AlertDialog.Builder(activity); new Thread(new Runnable() {
if(showCurrentGpx){ @Override
list.add(0, getString(R.string.show_current_gpx_title)); public void run() {
} GPXFile r = null;
builder.setItems(list.toArray(new String[list.size()]), new DialogInterface.OnClickListener() { for(String fname : filename) {
final File f = new File(dir, fname);
@Override GPXFile res = GPXUtilities.loadGPXFile(activity.getMyApplication(), f, convertCloudmade);
public void onClick(DialogInterface dialog, int which) { GPXUtilities.mergeGPXFileInto(res, r);
dialog.dismiss(); r = res;
if(showCurrentGpx && which == 0){ }
callbackWithObject.processResult(null); final GPXFile res = r;
} else { if (res != null) {
final ProgressDialog dlg = ProgressDialog.show(activity, getString(R.string.loading), dlg.dismiss();
getString(R.string.loading_data)); activity.runOnUiThread(new Runnable() {
final File f = new File(dir, list.get(which)); @Override
new Thread(new Runnable() { public void run() {
@Override if (res.warning != null) {
public void run() { AccessibleToast.makeText(activity, res.warning, Toast.LENGTH_LONG).show();
final GPXFile res = GPXUtilities.loadGPXFile(activity.getMyApplication(), f, convertCloudmade); } else {
dlg.dismiss(); callbackWithObject.processResult(res);
activity.runOnUiThread(new Runnable() { }
@Override }
public void run() { });
if (res.warning != null) {
AccessibleToast.makeText(activity, res.warning, Toast.LENGTH_LONG).show();
} else {
callbackWithObject.processResult(res);
}
}
});
}
}, "Loading gpx").start(); //$NON-NLS-1$
}
} }
});
AlertDialog dlg = builder.show();
try {
dlg.getListView().setFastScrollEnabled(true);
} catch(Exception e) {
// java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
// Unknown reason but on some devices fail
} }
}
}, "Loading gpx").start(); //$NON-NLS-1$
} }
private void selectPOIFilterLayer(final OsmandMapTileView mapView){ private void selectPOIFilterLayer(final OsmandMapTileView mapView){

View file

@ -41,7 +41,7 @@ public class RouteAnimation {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
ma.getMapLayers().selectGPXFileLayer(new CallbackWithObject<GPXUtilities.GPXFile>() { ma.getMapLayers().selectGPXFileLayer(true, false, false, new CallbackWithObject<GPXUtilities.GPXFile>() {
@Override @Override
public boolean processResult(GPXUtilities.GPXFile result) { public boolean processResult(GPXUtilities.GPXFile result) {
@ -50,7 +50,7 @@ public class RouteAnimation {
startAnimationThread(routingHelper, ma, prms.points, true, speedup.getProgress() + 1); startAnimationThread(routingHelper, ma, prms.points, true, speedup.getProgress() + 1);
return true; return true;
} }
}, true, false); });
} }
}); });

View file

@ -33,7 +33,6 @@ public class YandexTrafficAdapter extends MapTileAdapter {
@Override @Override
public void onInit() { public void onInit() {
AccessibleToast.makeText(view.getContext(), R.string.thanks_yandex_traffic, Toast.LENGTH_LONG).show();
} }
@Override @Override