Android通讯录开发之通讯录联系人搜索功能最新实现

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               
Android通讯录开发之通讯录联系人搜索功能最新实现


2014年1月13日
之前的有两篇博客介绍了如何解决通讯录搜索功能的问题,那些方法都是从网上搜集,然后经过自己整理试验之后的,但在项目测试人员给我反馈,似乎还是存在一些问题,比如一些简拼没能搜出,或者简拼的转换有了问题,主要是因为中文的转换为简拼还是有点麻烦的,不同的编码支持的汉字又不同,比如gb2312编码支持汉字6763个汉字,并且分为两级,一级汉字3755个,二级汉字3008个,还对这两级汉字进行了分区,一级汉字是按拼音排序,二级汉字按笔画排序,所以网上提供的一些方法并没有覆盖绝大部分的汉字,才会导致有些简拼无法转换的现象。所以我还是抛弃了之前的方法,因为还是无法满足实现简拼搜索的要求。
下面小巫提供另外一个工具类,是目前我负责的项目最新的实现
/* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.suntek.mobilemeeting.utils;import android.text.TextUtils;import android.util.Log;import java.text.Collator;import java.util.ArrayList;import java.util.Locale;/** * An object to convert Chinese character to its corresponding pinyin string. For characters with * multiple possible pinyin string, only one is selected according to collator. Polyphone is not * supported in this implementation. This class is implemented to achieve the best runtime * performance and minimum runtime resources with tolerable sacrifice of accuracy. This * implementation highly depends on zh_CN ICU collation data and must be always synchronized with * ICU. * * Currently this file is aligned to zh.txt in ICU 4.6 */public class HanziToPinyin {    private static final String TAG = "HanziToPinyin";    // Turn on this flag when we want to check internal data structure.    private static final boolean DEBUG = false;    /**     * Unihans array.     *     * Each unihans is the first one within same pinyin when collator is zh_CN.     */    public static final char[] UNIHANS = {            '\u963f', '\u54ce', '\u5b89', '\u80ae', '\u51f9', '\u516b',            '\u6300', '\u6273', '\u90a6', '\u52f9', '\u9642', '\u5954',            '\u4f3b', '\u5c44', '\u8fb9', '\u706c', '\u618b', '\u6c43',            '\u51ab', '\u7676', '\u5cec', '\u5693', '\u5072', '\u53c2',            '\u4ed3', '\u64a1', '\u518a', '\u5d7e', '\u66fd', '\u66fe',            '\u5c64', '\u53c9', '\u8286', '\u8fbf', '\u4f25', '\u6284',            '\u8f66', '\u62bb', '\u6c88', '\u6c89', '\u9637', '\u5403',            '\u5145', '\u62bd', '\u51fa', '\u6b3b', '\u63e3', '\u5ddb',            '\u5205', '\u5439', '\u65fe', '\u9034', '\u5472', '\u5306',            '\u51d1', '\u7c97', '\u6c46', '\u5d14', '\u90a8', '\u6413',            '\u5491', '\u5446', '\u4e39', '\u5f53', '\u5200', '\u561a',            '\u6265', '\u706f', '\u6c10', '\u55f2', '\u7538', '\u5201',            '\u7239', '\u4e01', '\u4e1f', '\u4e1c', '\u543a', '\u53be',            '\u8011', '\u8968', '\u5428', '\u591a', '\u59b8', '\u8bf6',            '\u5940', '\u97a5', '\u513f', '\u53d1', '\u5e06', '\u531a',            '\u98de', '\u5206', '\u4e30', '\u8985', '\u4ecf', '\u7d11',            '\u4f15', '\u65ee', '\u4f85', '\u7518', '\u5188', '\u768b',            '\u6208', '\u7ed9', '\u6839', '\u522f', '\u5de5', '\u52fe',            '\u4f30', '\u74dc', '\u4e56', '\u5173', '\u5149', '\u5f52',            '\u4e28', '\u5459', '\u54c8', '\u548d', '\u4f44', '\u592f',            '\u8320', '\u8bc3', '\u9ed2', '\u62eb', '\u4ea8', '\u5677',            '\u53ff', '\u9f41', '\u4e6f', '\u82b1', '\u6000', '\u72bf',            '\u5ddf', '\u7070', '\u660f', '\u5419', '\u4e0c', '\u52a0',            '\u620b', '\u6c5f', '\u827d', '\u9636', '\u5dfe', '\u5755',            '\u5182', '\u4e29', '\u51e5', '\u59e2', '\u5658', '\u519b',            '\u5494', '\u5f00', '\u520a', '\u5ffc', '\u5c3b', '\u533c',            '\u808e', '\u52a5', '\u7a7a', '\u62a0', '\u625d', '\u5938',            '\u84af', '\u5bbd', '\u5321', '\u4e8f', '\u5764', '\u6269',            '\u5783', '\u6765', '\u5170', '\u5577', '\u635e', '\u808b',            '\u52d2', '\u5d1a', '\u5215', '\u4fe9', '\u5941', '\u826f',            '\u64a9', '\u5217', '\u62ce', '\u5222', '\u6e9c', '\u56d6',            '\u9f99', '\u779c', '\u565c', '\u5a08', '\u7567', '\u62a1',            '\u7f57', '\u5463', '\u5988', '\u57cb', '\u5ada', '\u7264',            '\u732b', '\u4e48', '\u5445', '\u95e8', '\u753f', '\u54aa',            '\u5b80', '\u55b5', '\u4e5c', '\u6c11', '\u540d', '\u8c2c',            '\u6478', '\u54de', '\u6bea', '\u55ef', '\u62cf', '\u8149',            '\u56e1', '\u56d4', '\u5b6c', '\u7592', '\u5a1e', '\u6041',            '\u80fd', '\u59ae', '\u62c8', '\u5b22', '\u9e1f', '\u634f',            '\u56dc', '\u5b81', '\u599e', '\u519c', '\u7fba', '\u5974',            '\u597b', '\u759f', '\u9ec1', '\u90cd', '\u5594', '\u8bb4',            '\u5991', '\u62cd', '\u7705', '\u4e53', '\u629b', '\u5478',            '\u55b7', '\u5309', '\u4e15', '\u56e8', '\u527d', '\u6c15',            '\u59d8', '\u4e52', '\u948b', '\u5256', '\u4ec6', '\u4e03',            '\u6390', '\u5343', '\u545b', '\u6084', '\u767f', '\u4eb2',            '\u72c5', '\u828e', '\u4e18', '\u533a', '\u5cd1', '\u7f3a',            '\u590b', '\u5465', '\u7a63', '\u5a06', '\u60f9', '\u4eba',            '\u6254', '\u65e5', '\u8338', '\u53b9', '\u909a', '\u633c',            '\u5827', '\u5a51', '\u77a4', '\u637c', '\u4ee8', '\u6be2',            '\u4e09', '\u6852', '\u63bb', '\u95aa', '\u68ee', '\u50e7',            '\u6740', '\u7b5b', '\u5c71', '\u4f24', '\u5f30', '\u5962',            '\u7533', '\u8398', '\u6552', '\u5347', '\u5c38', '\u53ce',            '\u4e66', '\u5237', '\u8870', '\u95e9', '\u53cc', '\u8c01',            '\u542e', '\u8bf4', '\u53b6', '\u5fea', '\u635c', '\u82cf',            '\u72fb', '\u590a', '\u5b59', '\u5506', '\u4ed6', '\u56fc',            '\u574d', '\u6c64', '\u5932', '\u5fd1', '\u71a5', '\u5254',            '\u5929', '\u65eb', '\u5e16', '\u5385', '\u56f2', '\u5077',            '\u51f8', '\u6e4d', '\u63a8', '\u541e', '\u4e47', '\u7a75',            '\u6b6a', '\u5f2f', '\u5c23', '\u5371', '\u6637', '\u7fc1',            '\u631d', '\u4e4c', '\u5915', '\u8672', '\u4eda', '\u4e61',            '\u7071', '\u4e9b', '\u5fc3', '\u661f', '\u51f6', '\u4f11',            '\u5401', '\u5405', '\u524a', '\u5743', '\u4e2b', '\u6079',            '\u592e', '\u5e7a', '\u503b', '\u4e00', '\u56d9', '\u5e94',            '\u54df', '\u4f63', '\u4f18', '\u625c', '\u56e6', '\u66f0',            '\u6655', '\u7b60', '\u7b7c', '\u5e00', '\u707d', '\u5142',            '\u5328', '\u50ae', '\u5219', '\u8d3c', '\u600e', '\u5897',            '\u624e', '\u635a', '\u6cbe', '\u5f20', '\u957f', '\u9577',            '\u4f4b', '\u8707', '\u8d1e', '\u4e89', '\u4e4b', '\u5cd9',            '\u5ea2', '\u4e2d', '\u5dde', '\u6731', '\u6293', '\u62fd',            '\u4e13', '\u5986', '\u96b9', '\u5b92', '\u5353', '\u4e72',            '\u5b97', '\u90b9', '\u79df', '\u94bb', '\u539c', '\u5c0a',            '\u6628', '\u5159', '\u9fc3', '\u9fc4', };    /**     * Pinyin array.     *     * Each pinyin is corresponding to unihans of same     * offset in the unihans array.     */    public static final byte[][] PINYINS = {            { 65,   0,   0,   0,   0,   0}, { 6573,   0,   0,   0,   0},            { 6578,   0,   0,   0,   0}, { 657871,   0,   0,   0},            { 6579,   0,   0,   0,   0}, { 6665,   0,   0,   0,   0},            { 666573,   0,   0,   0}, { 666578,   0,   0,   0},            { 66657871,   0,   0}, { 666579,   0,   0,   0},            { 666973,   0,   0,   0}, { 666978,   0,   0,   0},            { 66697871,   0,   0}, { 6673,   0,   0,   0,   0},            { 66736578,   0,   0}, { 66736579,   0,   0},            { 667369,   0,   0,   0}, { 667378,   0,   0,   0},            { 66737871,   0,   0}, { 6679,   0,   0,   0,   0},            { 6685,   0,   0,   0,   0}, { 6765,   0,   0,   0,   0},            { 676573,   0,   0,   0}, { 676578,   0,   0,   0},            { 67657871,   0,   0}, { 676579,   0,   0,   0},            { 6769,   0,   0,   0,   0}, { 676978,   0,   0,   0},            { 67697871,   0,   0}, { 90697871,   0,   0},            { 67697871,   0,   0}, { 677265,   0,   0,   0},            { 67726573,   0,   0}, { 67726578,   0,   0},            { 6772657871,   0}, { 67726579,   0,   0},            { 677269,   0,   0,   0}, { 67726978,   0,   0},            { 83726978,   0,   0}, { 67726978,   0,   0},            { 6772697871,   0}, { 677273,   0,   0,   0},            { 6772797871,   0}, { 67727985,   0,   0},            { 677285,   0,   0,   0}, { 67728565,   0,   0},            { 6772856573,   0}, { 6772856578,   0},            { 677285657871}, { 67728573,   0,   0},            { 67728578,   0,   0}, { 67728579,   0,   0},            { 6773,   0,   0,   0,   0}, { 67797871,   0,   0},            { 677985,   0,   0,   0}, { 6785,   0,   0,   0,   0},            { 67856578,   0,   0}, { 678573,   0,   0,   0},            { 678578,   0,   0,   0}, { 678579,   0,   0,   0},            { 6865,   0,   0,   0,   0}, { 686573,   0,   0,   0},            { 686578,   0,   0,   0}, { 68657871,   0,   0},            { 686579,   0,   0,   0}, { 6869,   0,   0,   0,   0},            { 686978,   0,   0,   0}, { 68697871,   0,   0},            { 6873,   0,   0,   0,   0}, { 687365,   0,   0,   0},            { 68736578,   0,   0}, { 68736579,   0,   0},            { 687369,   0,   0,   0}, { 68737871,   0,   0},            { 687385,   0,   0,   0}, { 68797871,   0,   0},            { 687985,   0,   0,   0}, { 6885,   0,   0,   0,   0},            { 68856578,   0,   0}, { 688573,   0,   0,   0},            { 688578,   0,   0,   0}, { 688579,   0,   0,   0},            { 69,   0,   0,   0,   0,   0}, { 6973,   0,   0,   0,   0},            { 6978,   0,   0,   0,   0}, { 697871,   0,   0,   0},            { 6982,   0,   0,   0,   0}, { 7065,   0,   0,   0,   0},            { 706578,   0,   0,   0}, { 70657871,   0,   0},            { 706973,   0,   0,   0}, { 706978,   0,   0,   0},            { 70697871,   0,   0}, { 70736579,   0,   0},            { 7079,   0,   0,   0,   0}, { 707985,   0,   0,   0},            { 7085,   0,   0,   0,   0}, { 7165,   0,   0,   0,   0},            { 716573,   0,   0,   0}, { 716578,   0,   0,   0},            { 71657871,   0,   0}, { 716579,   0,   0,   0},            { 7169,   0,   0,   0,   0}, { 716973,   0,   0,   0},            { 716978,   0,   0,   0}, { 71697871,   0,   0},            { 71797871,   0,   0}, { 717985,   0,   0,   0},            { 7185,   0,   0,   0,   0}, { 718565,   0,   0,   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值