Java Code Examples for android.widget.Filter#FilterResults

The following examples show how to use android.widget.Filter#FilterResults . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MusicFilter.java    From PlayWidget with MIT License 6 votes vote down vote up
@NonNull
@Override
protected Filter.FilterResults performFilteringImpl(CharSequence constraint) {
    Filter.FilterResults results = new Filter.FilterResults();
    if (TextUtils.isEmpty(constraint) || TextUtils.isEmpty(constraint.toString().trim())) {
        results.count = -1;
        return results;
    }
    String str = constraint.toString().trim();
    List<MusicItem> result = new ArrayList<>();
    int size = getNonFilteredCount();
    for (int i = 0; i < size; i++) {
        MusicItem item = getNonFilteredItem(i);
        if (
                check(str, item.title())
                        || check(str, item.album())
                        || check(str, item.artist())
                ) {
            result.add(item);
        }
    }
    results.count = result.size();
    results.values = result;
    return results;
}
 
Example 2
Source File: TimezoneAdapter.java    From Travel-Mate with MIT License 6 votes vote down vote up
@Override
protected Filter.FilterResults performFiltering(CharSequence constraint) {
    List<String> matchingTimezones = new ArrayList<>();
    if (TextUtils.isEmpty(constraint)) {
        matchingTimezones.addAll(TimezoneAdapter.this.mTimezones);
    } else {
        String pattern = constraint.toString().toLowerCase().trim();
        for (String timezone : TimezoneAdapter.this.mTimezones) {
            if (timezone.toLowerCase().contains(pattern)) {
                matchingTimezones.add(timezone);
            }
        }
    }

    Filter.FilterResults filterResults = new Filter.FilterResults();
    filterResults.values = matchingTimezones;
    filterResults.count = matchingTimezones.size();

    return filterResults;
}
 
Example 3
Source File: ContactsEntryAdapter.java    From emerald-dialer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Filter.FilterResults performFiltering(CharSequence constraint) {
	Filter.FilterResults results = new FilterResults();
	ArrayList<RegexQueryResult> resultsList = new ArrayList<RegexQueryResult>();
	if (rawFiltering) {
		filterRaw(resultsList, constraint);
	} else {	
		filterWithRegex(resultsList, constraint);
	}
	
	Collections.sort(resultsList);
	results.values = resultsList;
	results.count = resultsList.size();
	return results;
}
 
Example 4
Source File: CursorFilter.java    From AppCodeArchitecture with Apache License 2.0 5 votes vote down vote up
@Override
protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
    Cursor oldCursor = mClient.getCursor();

    if (results.values != null && results.values != oldCursor) {
        mClient.changeCursor((Cursor) results.values);
    }
}
 
Example 5
Source File: ContactsEntryAdapter.java    From emerald-dialer with GNU General Public License v3.0 4 votes vote down vote up
protected void publishResults(CharSequence constraint, Filter.FilterResults results) {
	regexQueryResults = ((ArrayList<RegexQueryResult>) results.values);
	notifyDataSetChanged();
}