基于qwertySearch和T9Search实现的通讯录

基于qwertySearch 和 T9Search实现的通讯录

作者简书地址:http://www.jianshu.com/p/3c54cc71e238

官方github地址:https://github.com/handsomezhou/PinyinSearchLibrary

我的github地址: https://github.com/yin13753884368/qwertySearch

Function call in detail:
Import packages when use PinyinSearch Library(Dependent on pinyin4j-x.x.x.jar):
import com.pinyinsearch.util.*;
import com.pinyinsearch.model.*;

The first step:  Data parsing  (ps:Must init baseData of PinyinSearchUnit before parse)
    * (PinyinUtil.parse(...))
The second step: Data matching 
    * (T9Util.match(...) or QwertyUtil.match(...))

For details, please see project ContactsSearch and AppSearch.
使用要点:
//1.用Searcy初始化 PinyinSearchUnit
namePinyinSearchUnit = new PinyinSearchUnit(itemWordName);
//2.初始化 初始化之前先new PinyinSearchUnit
PinyinUtil.parse(namePinyinSearchUnit);
//3.去匹配,输出汉字
    if (headName.contains(lowerCase.substring(0, 1))) {
        if (QwertyUtil.match(namePinyinSearchUnit, text)) {//search by name;
        string = namePinyinSearchUnit.getMatchKeyword().toString();
        //将要改变颜色的字体设置到bean
        itemCont.setColorName(string);
        // Log.d("call", "查 询...namePinyinSearchUnit===" + string + "....lowerCase===" + lowerCase + "..." + text);
        list.add(itemCont);

    }
使字体改变颜色
    /**
     * 使字体变色
     * @param baseText
     * @param highlightText if the string of highlightText is a subset of the string of baseText,highlight the string of highlightText.
     */
    public void showTextHighlight(String baseText, String highlightText) {

        if (baseText != null && highlightText != null && highlightText.length() > 0) {

            int index = baseText.indexOf(highlightText);
            if (index < 0) {
                this.setText(baseText);
                return;
            }

            int len = highlightText.length();
            /**
             *  "<u><font color=#FF8C00 >"+str+"</font></u>";   //with underline
             *  "<font color=#FF8C00 >"+str+"</font>";          //without underline
             *  //将颜色设置成蓝色
             *  <color name="dark_orange">#FF8C00</color>
             */
            Spanned spanned = Html.fromHtml(baseText.substring(0, index) + "<font color=#38ADFF >"
                    + baseText.substring(index, index + len) + "</font>"
                    + baseText.substring(index + len, baseText.length()));

            this.setText(spanned);
        } else {
            this.setText(baseText);
        }  
    }

通过bean设置进去需要改变的字体颜色,在adapter中更新

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值