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 DESELECT_ALL_ID = 2;
private static final int FILTER_EXISTING_REGIONS = 3;
private static final int DOWNLOAD_FILES_TYPE = 4;
/** dialogs **/
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, DESELECT_ALL_ID, 0, R.string.deselect_all);
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;
}
@ -294,8 +292,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
listAdapter.setIndexFiles(filtered, IndexItemCategory.categorizeIndexItems(getClientContext(), filtered));
listAdapter.notifyDataSetChanged();
} else if (item.getItemId() == DOWNLOAD_FILES_TYPE) {
selectDownloadType();
} else if(item.getItemId() == DESELECT_ALL_ID){
entriesToDownload.clear();
listAdapter.notifyDataSetInvalidated();
@ -308,7 +304,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
}
private void selectDownloadType() {
public void selectDownloadType() {
Builder bld = new AlertDialog.Builder(this);
final DownloadActivityType[] items = getDownloadTypes();
bld.setItems(toString(items), new DialogInterface.OnClickListener() {

View file

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

View file

@ -348,7 +348,7 @@ public class MapActivityLayers {
public void showGPXFileLayer(final OsmandMapTileView mapView){
final OsmandSettings settings = getApplication().getSettings();
selectGPXFileLayer(new CallbackWithObject<GPXFile>() {
selectGPXFileLayer(true, true, true, new CallbackWithObject<GPXFile>() {
@Override
public boolean processResult(GPXFile result) {
GPXFile toShow = result;
@ -375,13 +375,75 @@ public class MapActivityLayers {
mapView.refreshMap();
return true;
}
}, true, true);
});
}
public void selectGPXFileLayer(final CallbackWithObject<GPXFile> callbackWithObject, final boolean convertCloudmade,
final boolean showCurrentGpx) {
final List<String> list = new ArrayList<String>();
public void selectGPXFileLayer(final boolean convertCloudmade,
final boolean showCurrentGpx, final boolean multipleChoice, final CallbackWithObject<GPXFile> callbackWithObject) {
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()) {
File[] files = dir.listFiles();
if (files != null) {
@ -405,30 +467,25 @@ public class MapActivityLayers {
}
}
}
if(list.isEmpty()){
AccessibleToast.makeText(activity, R.string.gpx_files_not_found, Toast.LENGTH_LONG).show();
return list;
}
if(!list.isEmpty() || showCurrentGpx){
Builder builder = new AlertDialog.Builder(activity);
if(showCurrentGpx){
list.add(0, getString(R.string.show_current_gpx_title));
}
builder.setItems(list.toArray(new String[list.size()]), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if(showCurrentGpx && which == 0){
callbackWithObject.processResult(null);
} else {
private void loadGPXFileInDifferentThread(final CallbackWithObject<GPXFile> callbackWithObject,
final boolean convertCloudmade, final File dir, final String... filename) {
final ProgressDialog dlg = ProgressDialog.show(activity, getString(R.string.loading),
getString(R.string.loading_data));
final File f = new File(dir, list.get(which));
new Thread(new Runnable() {
@Override
public void run() {
final GPXFile res = GPXUtilities.loadGPXFile(activity.getMyApplication(), f, convertCloudmade);
GPXFile r = null;
for(String fname : filename) {
final File f = new File(dir, fname);
GPXFile res = GPXUtilities.loadGPXFile(activity.getMyApplication(), f, convertCloudmade);
GPXUtilities.mergeGPXFileInto(res, r);
r = res;
}
final GPXFile res = r;
if (res != null) {
dlg.dismiss();
activity.runOnUiThread(new Runnable() {
@Override
@ -441,21 +498,10 @@ public class MapActivityLayers {
}
});
}
}
}, "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
}
}
}
private void selectPOIFilterLayer(final OsmandMapTileView mapView){
final List<PoiFilter> userDefined = new ArrayList<PoiFilter>();

View file

@ -41,7 +41,7 @@ public class RouteAnimation {
@Override
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
public boolean processResult(GPXUtilities.GPXFile result) {
@ -50,7 +50,7 @@ public class RouteAnimation {
startAnimationThread(routingHelper, ma, prms.points, true, speedup.getProgress() + 1);
return true;
}
}, true, false);
});
}
});

View file

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