diff --git a/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java b/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java index 2c009b1387..c1db7f5461 100644 --- a/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/com/osmand/activities/DownloadIndexActivity.java @@ -108,7 +108,7 @@ public class DownloadIndexActivity extends ListActivity { final File fileToSave = resolveFileName(e.getKey(), regionName); if (fileToSave != null) { Builder builder = new AlertDialog.Builder(this); - File toCheck = new File(fileToSave.getParent(), fileToSave.getName().substring(fileToSave.getName().length() - 4) +".odb"); //$NON-NLS-1$ + File toCheck = new File(fileToSave.getParent(), fileToSave.getName().substring(0, fileToSave.getName().length() - 4) +".odb"); //$NON-NLS-1$ if(!toCheck.exists()){ builder.setMessage(MessageFormat.format(getString(R.string.download_question), regionName, e.getValue())); } else { @@ -176,14 +176,22 @@ public class DownloadIndexActivity extends ListActivity { try { FileOutputStream out = new FileOutputStream(file); URL url = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key); + URLConnection conn = url.openConnection(); + conn.setReadTimeout(30000); + conn.setConnectTimeout(30000); InputStream is = conn.getInputStream(); - impl.startTask(getString(R.string.downloading_file), conn.getContentLength()); + int length = conn.getContentLength(); + impl.startTask(getString(R.string.downloading_file), length); byte[] buffer = new byte[BUFFER_SIZE]; int read = 0; while((read = is.read(buffer)) != -1){ out.write(buffer, 0, read); impl.progress(read); + length -= read; + } + if(length > 0){ + throw new IOException("File was not fully read"); //$NON-NLS-1$ } out.close(); diff --git a/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java b/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java index 0e6967efb8..8f61db5374 100644 --- a/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java +++ b/OsmAnd/src/com/osmand/activities/EditingPOIActivity.java @@ -14,7 +14,9 @@ import java.net.MalformedURLException; import java.net.URL; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.http.HttpResponse; @@ -39,6 +41,8 @@ import android.app.AlertDialog.Builder; import android.content.Context; import android.content.DialogInterface; import android.content.res.Resources; +import android.text.Editable; +import android.text.TextWatcher; import android.util.Xml; import android.view.View; import android.widget.ArrayAdapter; @@ -172,6 +176,30 @@ public class EditingPOIActivity { } }); + typeText.addTextChangedListener(new TextWatcher(){ + + @Override + public void afterTextChanged(Editable s) { + String str = s.toString(); + AmenityType t = AmenityType.getAmenityMap().get(str); + if(t != null && a.getType() != t){ + a.setType(t); + typeButton.setText(AmenityType.toPublicString(t)); + updateSubTypesAdapter(t); + } + + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + }); + + typeButton.setOnClickListener(new View.OnClickListener(){ @Override @@ -235,13 +263,22 @@ public class EditingPOIActivity { dlg.show(); } + private void updateSubTypesAdapter(AmenityType t){ + Set subCategories = new LinkedHashSet(AmenityType.getSubCategories(t)); + for(String s : AmenityType.getAmenityMap().keySet()){ + if(!subCategories.contains(s)){ + subCategories.add(s); + } + } + + ArrayAdapter adapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.toArray()); + typeText.setAdapter(adapter); + } + private void updateType(Amenity a){ typeText.setText(a.getSubType()); typeButton.setText(AmenityType.toPublicString(a.getType())); - - List subCategories = AmenityType.getSubCategories(a.getType()); - ArrayAdapter adapter = new ArrayAdapter(ctx, R.layout.list_textview, subCategories.toArray()); - typeText.setAdapter(adapter); + updateSubTypesAdapter(a.getType()); } private void showWarning(final String msg){