From 8b8cb06104acbd35a84db3f79d09fd6a9464b087 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 24 Aug 2012 01:37:17 +0200 Subject: [PATCH] Fix span bug --- .../plus/activities/FontFitTextView.java | 4 ---- .../search/SearchByNameAbstractActivity.java | 21 +++++++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/FontFitTextView.java b/OsmAnd/src/net/osmand/plus/activities/FontFitTextView.java index 1f51ba49fa..6677e922c2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FontFitTextView.java +++ b/OsmAnd/src/net/osmand/plus/activities/FontFitTextView.java @@ -22,15 +22,11 @@ public class FontFitTextView extends TextView { public FontFitTextView(Context context, AttributeSet attrs) { super(context, attrs); - setSingleLine(); - setEllipsize(TruncateAt.MARQUEE); } // Default constructor override public FontFitTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); - setSingleLine(); - setEllipsize(TruncateAt.MARQUEE); } private void refitText(String text, int textWidth, int textHeight, boolean layout) { diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java index 6a884b19b6..3b710ae725 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchByNameAbstractActivity.java @@ -70,8 +70,10 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity protected Collator collator; protected NamesFilter namesFilter; private String currentFilter = ""; + private boolean initFilter = false; private String endingText = ""; private T endingObject; + private StyleSpan previousSpan; private CustomTitleBar titleBar; private static final Log log = LogUtil.getLog(SearchByNameAbstractActivity.class); @@ -189,15 +191,19 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity } f = f.substring(0, f.length() - endingText.length()); } - if (!currentFilter.equals(f)) { + if (!currentFilter.equals(f) || !initFilter) { currentFilter = f; + initFilter = true; progress.setVisibility(View.VISIBLE); namesFilter.cancelPreviousFilter(f); namesFilter.filter(f); } if(change) { - searchText.getText().clearSpans(); - searchText.getText().setSpan(new StyleSpan(Typeface.BOLD_ITALIC), currentFilter.length(), + if(previousSpan != null) { + searchText.getText().removeSpan(previousSpan); + } + previousSpan = new StyleSpan(Typeface.BOLD_ITALIC); + searchText.getText().setSpan(previousSpan, currentFilter.length(), currentFilter.length() + endingText.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } @@ -323,7 +329,7 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity String etext = endingText; endingText = ""; searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), ""); - searchText.setSelection(currentFilter.length()); + // searchText.setSelection(currentFilter.length()); } else if(msg.what == MESSAGE_ADD_ENTITY){ getListAdapter().add((T) msg.obj); if (add && currentFilter.length() > 0) { @@ -340,8 +346,11 @@ public abstract class SearchByNameAbstractActivity extends OsmandListActivity String etext = endingText; endingText = text; searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), text); - searchText.getText().clearSpans(); - searchText.getText().setSpan(new StyleSpan(Typeface.BOLD_ITALIC), currentFilter.length(), + 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());