fixing bugs

git-svn-id: https://osmand.googlecode.com/svn/trunk@355 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-15 21:17:28 +00:00
parent 75417448ad
commit 7edc854da3
2 changed files with 51 additions and 6 deletions

View file

@ -108,7 +108,7 @@ public class DownloadIndexActivity extends ListActivity {
final File fileToSave = resolveFileName(e.getKey(), regionName); final File fileToSave = resolveFileName(e.getKey(), regionName);
if (fileToSave != null) { if (fileToSave != null) {
Builder builder = new AlertDialog.Builder(this); 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()){ if(!toCheck.exists()){
builder.setMessage(MessageFormat.format(getString(R.string.download_question), regionName, e.getValue())); builder.setMessage(MessageFormat.format(getString(R.string.download_question), regionName, e.getValue()));
} else { } else {
@ -176,14 +176,22 @@ public class DownloadIndexActivity extends ListActivity {
try { try {
FileOutputStream out = new FileOutputStream(file); FileOutputStream out = new FileOutputStream(file);
URL url = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key); URL url = DownloaderIndexFromGoogleCode.getInputStreamToLoadIndex(key);
URLConnection conn = url.openConnection(); URLConnection conn = url.openConnection();
conn.setReadTimeout(30000);
conn.setConnectTimeout(30000);
InputStream is = conn.getInputStream(); 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]; byte[] buffer = new byte[BUFFER_SIZE];
int read = 0; int read = 0;
while((read = is.read(buffer)) != -1){ while((read = is.read(buffer)) != -1){
out.write(buffer, 0, read); out.write(buffer, 0, read);
impl.progress(read); impl.progress(read);
length -= read;
}
if(length > 0){
throw new IOException("File was not fully read"); //$NON-NLS-1$
} }
out.close(); out.close();

View file

@ -14,7 +14,9 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -39,6 +41,8 @@ import android.app.AlertDialog.Builder;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Xml; import android.util.Xml;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; 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(){ typeButton.setOnClickListener(new View.OnClickListener(){
@Override @Override
@ -235,13 +263,22 @@ public class EditingPOIActivity {
dlg.show(); dlg.show();
} }
private void updateSubTypesAdapter(AmenityType t){
Set<String> subCategories = new LinkedHashSet<String>(AmenityType.getSubCategories(t));
for(String s : AmenityType.getAmenityMap().keySet()){
if(!subCategories.contains(s)){
subCategories.add(s);
}
}
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
typeText.setAdapter(adapter);
}
private void updateType(Amenity a){ private void updateType(Amenity a){
typeText.setText(a.getSubType()); typeText.setText(a.getSubType());
typeButton.setText(AmenityType.toPublicString(a.getType())); typeButton.setText(AmenityType.toPublicString(a.getType()));
updateSubTypesAdapter(a.getType());
List<String> subCategories = AmenityType.getSubCategories(a.getType());
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
typeText.setAdapter(adapter);
} }
private void showWarning(final String msg){ private void showWarning(final String msg){