From 391d2a2f3487abe13b2a086ad898c8dbbd699ed7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 18 Nov 2012 13:41:22 +0100 Subject: [PATCH] Fix search issue --- OsmAnd/res/values/strings.xml | 1 + .../search/SearchBuildingByNameActivity.java | 5 + .../search/SearchByNameAbstractActivity.java | 107 ++++++++---------- .../download/DownloadOsmandIndexesHelper.java | 2 +- 4 files changed, 54 insertions(+), 61 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 623dd7c5dd..d546bc0e86 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 1. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + No buildings found. Search city incrementally. Search villages/postcode Select when to display roads-only maps: diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java index c626bec772..eeb4ba884d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchBuildingByNameActivity.java @@ -14,6 +14,7 @@ import net.osmand.plus.R; import net.osmand.plus.RegionAddressRepository; import android.os.AsyncTask; import android.view.View; +import android.widget.Toast; public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity { private RegionAddressRepository region; @@ -40,6 +41,10 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity extends OsmandListActivity @Override public void afterTextChanged(Editable s) { - querySearch(s.toString()); - updateSpan(currentFilter, endingText); + String newFilter = s.toString(); + String newEndingText = endingText; + if (newEndingText.length() > 0) { + while(!newFilter.endsWith(newEndingText) && newEndingText.length() > 0) { + newEndingText = newEndingText.substring(1); + } + newFilter = newFilter.substring(0, newFilter.length() - newEndingText.length()); + } + updateTextBox(newFilter, newEndingText, endingObject, false); + querySearch(newFilter); + } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { @@ -110,13 +119,6 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity }); // Not perfect // searchText.setOnClickListener(new OnClickListener() { -// String previousSelect = ""; -// @Override -// public void onClick(View v) { -// if(!previousSelect.equals(endingText) && endingText.length() > 0) { -// previousSelect = endingText; -// itemSelectedBase(endingObject, v); -// } // } // }); searchText.setImeOptions(EditorInfo.IME_ACTION_DONE); @@ -186,35 +188,38 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity } public void research() { - String s = getCurrentFilter(); - currentFilter = ""; - querySearch(s); + initFilter = false; + querySearch(currentFilter); } - public void querySearch(final String filter) { - String f = filter; - if (endingText.length() > 0) { - while(!f.endsWith(endingText) && endingText.length() > 0) { - endingText = endingText.substring(1); - } - f = f.substring(0, f.length() - endingText.length()); - } - if (!currentFilter.equals(f) || !initFilter) { - currentFilter = f; + + private void querySearch(final String filter) { + if (!currentFilter.equals(filter) || !initFilter) { + currentFilter = filter; initFilter = true; progress.setVisibility(View.VISIBLE); - namesFilter.cancelPreviousFilter(f); - namesFilter.filter(f); + namesFilter.cancelPreviousFilter(filter); + namesFilter.filter(filter); } } - private void updateSpan(String currentFilter, String endingText) { - if(previousSpan != null) { - searchText.getText().removeSpan(previousSpan); + private void updateTextBox(String currentFilter, String locEndingText, T obj, boolean updateText) { + String prevEndtext = endingText; + endingText = locEndingText; + endingObject = obj; + if(updateText) { + searchText.getText().replace(currentFilter.length(), currentFilter.length() + prevEndtext.length(), locEndingText); } - if (endingText.length() > 0) { + if (previousSpan != null) { + searchText.getText().removeSpan(previousSpan); + previousSpan = null; + } + if (locEndingText.length() > 0) { previousSpan = new StyleSpan(Typeface.BOLD_ITALIC); - searchText.getText().setSpan(previousSpan, currentFilter.length(), currentFilter.length() + endingText.length(), + searchText.getText().setSpan(previousSpan, currentFilter.length(), currentFilter.length() + locEndingText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (searchText.getSelectionEnd() > currentFilter.length()) { + searchText.setSelection(currentFilter.length()); + } } } @@ -318,51 +323,33 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity minimalIndex = Integer.MAX_VALUE; minimalText = null; getListAdapter().clear(); - endingObject = null; if(currentFilter.length() == 0) { endingMap.clear(); } - String etext = endingText; - endingText = ""; - if(previousSpan != null) { - searchText.getText().removeSpan(previousSpan); - } - searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), ""); - // searchText.setSelection(currentFilter.length()); + updateTextBox(currentFilter, "", null, true); } else if(msg.what == MESSAGE_ADD_ENTITY){ getListAdapter().add((T) msg.obj); if (currentFilter.length() > 0) { - String text = getShortText((T) msg.obj); - int entries = !endingMap.containsKey(text) ? 0 : endingMap.get(text); + String shortText = getShortText((T) msg.obj); + int entries = !endingMap.containsKey(shortText) ? 0 : endingMap.get(shortText); if (entries < minimalIndex) { if(minimalText != null) { endingMap.put(minimalText, endingMap.get(minimalText) - 1); } minimalIndex = entries; - minimalText = text; - endingMap.put(text, entries + 1); - if (text.toLowerCase().startsWith(currentFilter.toLowerCase())) { - text = text.substring(currentFilter.length()); + minimalText = shortText; + endingMap.put(shortText, entries + 1); + String locEndingText; + if (shortText.toLowerCase().startsWith(currentFilter.toLowerCase())) { + locEndingText = shortText.substring(currentFilter.length()); } else { - text = " - " + text; + locEndingText = " - " + shortText; } - if (text.length() > MAX_VISIBLE_NAME) { - text = text.substring(0, MAX_VISIBLE_NAME) + ".."; + if (locEndingText.length() > MAX_VISIBLE_NAME) { + locEndingText = locEndingText.substring(0, MAX_VISIBLE_NAME) + ".."; } - String etext = endingText; - endingText = text; - searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), text); - if (previousSpan != null) { - searchText.getText().removeSpan(previousSpan); - } - previousSpan = new StyleSpan(Typeface.BOLD_ITALIC); - searchText.getText().setSpan(previousSpan, currentFilter.length(), currentFilter.length() + text.length(), - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); - if (searchText.getSelectionEnd() > currentFilter.length()) { - searchText.setSelection(currentFilter.length()); - } - // endingButton.setText(text + ".."); - endingObject = (T) msg.obj; + updateTextBox(currentFilter, locEndingText, (T) msg.obj, true); + } } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index b5fa6883ac..e25df71644 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -36,7 +36,7 @@ import android.widget.Toast; public class DownloadOsmandIndexesHelper { private final static Log log = LogUtil.getLog(DownloadOsmandIndexesHelper.class); - public static final String INDEX_DOWNLOAD_DOMAIN = "new.osmand.net"; + public static final String INDEX_DOWNLOAD_DOMAIN = "download.osmand.net"; public static IndexFileList getIndexesList(Context ctx) { PackageManager pm =ctx.getPackageManager();