Fix span bug
This commit is contained in:
parent
cf37eb45bf
commit
8b8cb06104
2 changed files with 15 additions and 10 deletions
|
@ -22,15 +22,11 @@ public class FontFitTextView extends TextView {
|
||||||
|
|
||||||
public FontFitTextView(Context context, AttributeSet attrs) {
|
public FontFitTextView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
setSingleLine();
|
|
||||||
setEllipsize(TruncateAt.MARQUEE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default constructor override
|
// Default constructor override
|
||||||
public FontFitTextView(Context context, AttributeSet attrs, int defStyle) {
|
public FontFitTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
setSingleLine();
|
|
||||||
setEllipsize(TruncateAt.MARQUEE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refitText(String text, int textWidth, int textHeight, boolean layout) {
|
private void refitText(String text, int textWidth, int textHeight, boolean layout) {
|
||||||
|
|
|
@ -70,8 +70,10 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
||||||
protected Collator collator;
|
protected Collator collator;
|
||||||
protected NamesFilter namesFilter;
|
protected NamesFilter namesFilter;
|
||||||
private String currentFilter = "";
|
private String currentFilter = "";
|
||||||
|
private boolean initFilter = false;
|
||||||
private String endingText = "";
|
private String endingText = "";
|
||||||
private T endingObject;
|
private T endingObject;
|
||||||
|
private StyleSpan previousSpan;
|
||||||
private CustomTitleBar titleBar;
|
private CustomTitleBar titleBar;
|
||||||
private static final Log log = LogUtil.getLog(SearchByNameAbstractActivity.class);
|
private static final Log log = LogUtil.getLog(SearchByNameAbstractActivity.class);
|
||||||
|
|
||||||
|
@ -189,15 +191,19 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
||||||
}
|
}
|
||||||
f = f.substring(0, f.length() - endingText.length());
|
f = f.substring(0, f.length() - endingText.length());
|
||||||
}
|
}
|
||||||
if (!currentFilter.equals(f)) {
|
if (!currentFilter.equals(f) || !initFilter) {
|
||||||
currentFilter = f;
|
currentFilter = f;
|
||||||
|
initFilter = true;
|
||||||
progress.setVisibility(View.VISIBLE);
|
progress.setVisibility(View.VISIBLE);
|
||||||
namesFilter.cancelPreviousFilter(f);
|
namesFilter.cancelPreviousFilter(f);
|
||||||
namesFilter.filter(f);
|
namesFilter.filter(f);
|
||||||
}
|
}
|
||||||
if(change) {
|
if(change) {
|
||||||
searchText.getText().clearSpans();
|
if(previousSpan != null) {
|
||||||
searchText.getText().setSpan(new StyleSpan(Typeface.BOLD_ITALIC), currentFilter.length(),
|
searchText.getText().removeSpan(previousSpan);
|
||||||
|
}
|
||||||
|
previousSpan = new StyleSpan(Typeface.BOLD_ITALIC);
|
||||||
|
searchText.getText().setSpan(previousSpan, currentFilter.length(),
|
||||||
currentFilter.length() + endingText.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
currentFilter.length() + endingText.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +329,7 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
||||||
String etext = endingText;
|
String etext = endingText;
|
||||||
endingText = "";
|
endingText = "";
|
||||||
searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), "");
|
searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), "");
|
||||||
searchText.setSelection(currentFilter.length());
|
// searchText.setSelection(currentFilter.length());
|
||||||
} else if(msg.what == MESSAGE_ADD_ENTITY){
|
} else if(msg.what == MESSAGE_ADD_ENTITY){
|
||||||
getListAdapter().add((T) msg.obj);
|
getListAdapter().add((T) msg.obj);
|
||||||
if (add && currentFilter.length() > 0) {
|
if (add && currentFilter.length() > 0) {
|
||||||
|
@ -340,8 +346,11 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
||||||
String etext = endingText;
|
String etext = endingText;
|
||||||
endingText = text;
|
endingText = text;
|
||||||
searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), text);
|
searchText.getText().replace(currentFilter.length(), currentFilter.length() + etext.length(), text);
|
||||||
searchText.getText().clearSpans();
|
if(previousSpan != null) {
|
||||||
searchText.getText().setSpan(new StyleSpan(Typeface.BOLD_ITALIC), currentFilter.length(),
|
searchText.getText().removeSpan(previousSpan);
|
||||||
|
}
|
||||||
|
previousSpan = new StyleSpan(Typeface.BOLD_ITALIC);
|
||||||
|
searchText.getText().setSpan(previousSpan, currentFilter.length(),
|
||||||
currentFilter.length() + text.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
currentFilter.length() + text.length() , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
if(searchText.getSelectionEnd() > currentFilter.length()) {
|
if(searchText.getSelectionEnd() > currentFilter.length()) {
|
||||||
searchText.setSelection(currentFilter.length());
|
searchText.setSelection(currentFilter.length());
|
||||||
|
|
Loading…
Reference in a new issue