├── .classpath ├── .gitattributes ├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── .project ├── .settings └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── PinyinSearch ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── PinyinSearch.iml ├── libs │ └── pinyin4j-2.5.0.jar ├── lint.xml ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── pinyinsearch │ ├── model │ ├── PinyinBaseUnit.java │ └── PinyinUnit.java │ └── util │ ├── PinyinUtil.java │ ├── QwertyMatchPinyinUnits.java │ ├── T9MatchPinyinUnits.java │ └── T9Util.java ├── README.md ├── citylist.iml ├── libs ├── BaiduLBS_Android.jar ├── armeabi-v7a │ ├── libBaiduMapSDK_v3_4_0_15.so │ └── liblocSDK5.so └── armeabi │ ├── libBaiduMapSDK_v3_4_0_15.so │ └── liblocSDK5.so ├── project.properties ├── res ├── anim │ ├── city_locating_anim.xml │ └── publicloading.xml ├── color │ └── wb_title_text_color_selector.xml ├── drawable-hdpi │ ├── btn_choose_city_normal.9.png │ ├── city_locate_failed.png │ ├── city_locate_success.png │ ├── city_locating_frame1.png │ ├── city_locating_frame2.png │ ├── city_locating_frame3.png │ ├── city_switch_pressed.9.png │ ├── common_alert_bg.9.png │ ├── publicloading1.png │ ├── wb_btn_off_normal.png │ ├── wb_btn_off_pressed.png │ ├── wb_letter_search_normal.png │ ├── wb_list_search_enabled.png │ ├── wb_list_search_icon.png │ ├── wb_list_search_pressed.png │ ├── wb_title_change_map_disenabled.png │ ├── wb_title_change_map_normal.png │ ├── wb_title_change_map_pressed.png │ ├── wb_title_drawable.9.png │ └── wb_title_search_disabled.png ├── drawable-xhdpi │ ├── bg_shop_search.9.png │ ├── bookingdetail_public_close.png │ ├── btn_gray_delete_sel.png │ ├── btn_gray_delete_unsel.png │ ├── btn_search_sel.9.png │ ├── btn_search_unsel.9.png │ ├── empty_page_search.png │ ├── ic_back_u.png │ ├── icon_search.png │ ├── topbar_bg.9.png │ ├── wb_back_btn_normal.png │ ├── wb_back_btn_pressed.png │ ├── wb_btn_off_normal.png │ ├── wb_btn_off_pressed.png │ ├── wb_list_search_icon.png │ ├── wb_list_search_pressed.png │ ├── wb_title_change_map_normal.png │ ├── wb_title_change_map_pressed.png │ ├── wb_title_map_disabled.png │ └── wb_title_search_disabled.png ├── drawable │ ├── btn_gray_delete_selector.xml │ ├── btn_search_selector.xml │ ├── city_hot_grid_item.xml │ ├── city_item_bg.xml │ ├── city_search_bg.xml │ ├── clickable_white_to_gray.xml │ ├── icon.png │ ├── wb_back_btn.xml │ ├── wb_btn_off.xml │ ├── wb_change_city_click.xml │ ├── wb_list_search_btn.xml │ └── wb_title_change_map_btn.xml ├── layout │ ├── activity_home.xml │ ├── bookname_list.xml │ ├── city_change_dailog.xml │ ├── city_hot_item_layout.xml │ ├── city_locate_layout.xml │ ├── city_search_list_item.xml │ ├── empty_search_city_item.xml │ ├── overlay.xml │ ├── public_cityhot.xml │ ├── public_cityhot_allcity.xml │ ├── public_cityhot_header_padding.xml │ ├── public_cityhot_header_padding_blank.xml │ ├── public_cityhot_header_searchview.xml │ ├── public_cityhot_item.xml │ ├── public_title.xml │ └── searchlayout.xml ├── raw │ └── china_city_name └── values │ ├── color.xml │ ├── dimens.xml │ ├── drawables.xml │ ├── strings.xml │ └── styles.xml ├── screenshot.png └── src └── com └── gugalor ├── adapter ├── HotCityGridAdapter.java ├── MyGridView.java └── TitleButton.java ├── application └── PinyinSearchApplication.java ├── citylist ├── CityList.java ├── CityModel.java ├── CitysearchAdapter.java ├── CitysearchNonAdapter.java ├── DBManager.java ├── MyLetterListView.java ├── Setting.java ├── citychangdialog.java ├── home.java └── searchactivity.java ├── helper └── ContactsHelper.java └── model ├── BaseContacts.java └── Contacts.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | /*/build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | citylist -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 29 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | home 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /PinyinSearch/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /PinyinSearch/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | PinyinSearch 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /PinyinSearch/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /PinyinSearch/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /PinyinSearch/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /PinyinSearch/PinyinSearch.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /PinyinSearch/libs/pinyin4j-2.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/PinyinSearch/libs/pinyin4j-2.5.0.jar -------------------------------------------------------------------------------- /PinyinSearch/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /PinyinSearch/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /PinyinSearch/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-20 15 | android.library=true 16 | -------------------------------------------------------------------------------- /PinyinSearch/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/PinyinSearch/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /PinyinSearch/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/PinyinSearch/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /PinyinSearch/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/PinyinSearch/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PinyinSearch/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PinyinSearch/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PinyinSearch/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PinyinSearch 4 | 5 | 6 | -------------------------------------------------------------------------------- /PinyinSearch/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /PinyinSearch/src/com/pinyinsearch/model/PinyinBaseUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 handsomezhou 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pinyinsearch.model; 18 | /** 19 | * As a single Pinyin units 20 | * for example: 21 | * "hao" ===>mOriginalString="hao"; mPinyin="hao";mNumber="426"; 22 | * "???hao" ===>mOriginalString="???hao"; mPinyin="???hao";mNumber="???426"; 23 | * "周" ===>mOriginalString="周"; mPinyin="zhou";mNumber="9468"; 24 | */ 25 | public class PinyinBaseUnit implements Cloneable{ 26 | private String mOriginalString; 27 | private String mPinyin; 28 | private String mNumber; 29 | 30 | public PinyinBaseUnit(){ 31 | 32 | } 33 | 34 | public PinyinBaseUnit(String originalString,String pinyin, String number) { 35 | super(); 36 | mOriginalString=originalString; 37 | mPinyin = pinyin; 38 | mNumber = number; 39 | } 40 | 41 | public String getOriginalString() { 42 | return mOriginalString; 43 | } 44 | 45 | public void setOriginalString(String originalString) { 46 | mOriginalString = originalString; 47 | } 48 | 49 | public String getPinyin() { 50 | return mPinyin; 51 | } 52 | 53 | public void setPinyin(String pinyin) { 54 | mPinyin = pinyin; 55 | } 56 | 57 | public String getNumber() { 58 | return mNumber; 59 | } 60 | 61 | public void setNumber(String number) { 62 | mNumber = number; 63 | } 64 | 65 | @Override 66 | protected Object clone() throws CloneNotSupportedException { 67 | return super.clone(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /PinyinSearch/src/com/pinyinsearch/model/PinyinUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 handsomezhou 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pinyinsearch.model; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | 22 | /** 23 | * PinyinUnit as a base data structure to save the string that Chinese characters converted to Pinyin characters. 24 | * for example: 25 | * Reference: http://www.cnblogs.com/bomo/archive/2012/12/25/2833081.html 26 | * Chinese characters:"Hi你说了什么git???" 27 | * Pinyin: 28 | * Hi-Hi ===>mPinyin=false, mPinyinBaseUnitIndex.size=1, mStartPosition=0 29 | * {[mPinyinBaseUnitIndex.get(0).getPinyin()="Hi",mPinyinBaseUnitIndex.get(0).getNumber="Hi"];} 30 | * 31 | * 你->ni3 ===>mPinyin=true, mPinyinBaseUnitIndex.size=1, mStartPosition=2 32 | * {[mPinyinBaseUnitIndex.get(0).getPinyin()="ni",mPinyinBaseUnitIndex.get(0).getNumber="64"];} 33 | * 34 | * 说->shuo1,shui4,yue4 ===>mPinyin=true, mPinyinBaseUnitIndex.size=3, mStartPosition=3 35 | * { 36 | * [mPinyinBaseUnitIndex.get(0).getPinyin()="shuo",mPinyinBaseUnitIndex.get(0).getNumber="7486"]; 37 | * [mPinyinBaseUnitIndex.get(1).getPinyin()="shui",mPinyinBaseUnitIndex.get(1).getNumber="7484"]; 38 | * [mPinyinBaseUnitIndex.get(2).getPinyin()="yue",mPinyinBaseUnitIndex.get(2).getNumber="983"];} 39 | * 40 | * 了->le5,liao3,liao4 ===>mPinyin=true, mPinyinBaseUnitIndex.size=2, mStartPosition=4 41 | * { 42 | * [mPinyinBaseUnitIndex.get(0).getPinyin()="le",mPinyinBaseUnitIndex.get(0).getNumber="53"]; 43 | * [mPinyinBaseUnitIndex.get(1).getPinyin()="liao",mPinyinBaseUnitIndex.get(1).getNumber="5426"];} 44 | * 45 | * 什->shen2,shi2,she2 ===>mPinyin=true, mPinyinBaseUnitIndex.size=3, mStartPosition=5 46 | * { 47 | * [mPinyinBaseUnitIndex.get(0).getPinyin()="shen",mPinyinBaseUnitIndex.get(0).getNumber="7436"]; 48 | * [mPinyinBaseUnitIndex.get(1).getPinyin()="shi",mPinyinBaseUnitIndex.get(1).getNumber="744"]; 49 | * [mPinyinBaseUnitIndex.get(2).getPinyin()="she",mPinyinBaseUnitIndex.get(2).getNumber="743"];} 50 | * 51 | * 么->me5,ma5,yao1 ===>mPinyin=true, mPinyinBaseUnitIndex.size=3, mStartPosition=6 52 | * { 53 | * [mPinyinBaseUnitIndex.get(0).getPinyin()="me",mPinyinBaseUnitIndex.get(0).getNumber="63"]; 54 | * [mPinyinBaseUnitIndex.get(1).getPinyin()="ma",mPinyinBaseUnitIndex.get(1).getNumber="62"]; 55 | * [mPinyinBaseUnitIndex.get(2).getPinyin()="yao",mPinyinBaseUnitIndex.get(2).getNumber="926"];} 56 | * 57 | * git???->git??? ===>mPinyin=false, mPinyinBaseUnitIndex.size=1, mStartPosition=7 58 | * {[mPinyinBaseUnitIndex.get(0).getPinyin()="git???",mPinyinBaseUnitIndex.get(0).getNumber="448???"];} 59 | * 60 | */ 61 | 62 | public class PinyinUnit implements Cloneable{ 63 | //Whether Pinyin 64 | private boolean mPinyin; 65 | private int mStartPosition; //save starting index position that the variables in the original string. 66 | /* 67 | * save the string which single Chinese characters Pinyin(include Multiple Pinyin),or continuous non-kanji characters. 68 | * if mPinyinBaseUnitIndex.size not more than 1, it means the is not Polyphonic characters. 69 | */ 70 | private List mPinyinBaseUnitIndex; 71 | 72 | public PinyinUnit() { 73 | mPinyin=false; 74 | mStartPosition=-1; 75 | mPinyinBaseUnitIndex=new ArrayList(); 76 | } 77 | 78 | public boolean isPinyin() { 79 | return mPinyin; 80 | } 81 | 82 | public void setPinyin(boolean pinyin) { 83 | mPinyin = pinyin; 84 | } 85 | 86 | public int getStartPosition() { 87 | return mStartPosition; 88 | } 89 | 90 | public void setStartPosition(int startPosition) { 91 | mStartPosition = startPosition; 92 | } 93 | 94 | public List getPinyinBaseUnitIndex() { 95 | return mPinyinBaseUnitIndex; 96 | } 97 | 98 | public void setStringIndex(List stringIndex) { 99 | mPinyinBaseUnitIndex = stringIndex; 100 | } 101 | 102 | @Override 103 | public Object clone() throws CloneNotSupportedException { 104 | PinyinUnit obj=(PinyinUnit)super.clone(); 105 | 106 | obj.mPinyinBaseUnitIndex=new ArrayList(); 107 | for(PinyinBaseUnit pbu:mPinyinBaseUnitIndex){ 108 | obj.mPinyinBaseUnitIndex.add((PinyinBaseUnit)pbu.clone()); 109 | } 110 | 111 | return obj; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /PinyinSearch/src/com/pinyinsearch/util/PinyinUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 handsomezhou 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pinyinsearch.util; 18 | 19 | import java.util.List; 20 | import net.sourceforge.pinyin4j.PinyinHelper; 21 | import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; 22 | import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; 23 | import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; 24 | import android.annotation.SuppressLint; 25 | import com.pinyinsearch.model.PinyinUnit; 26 | import com.pinyinsearch.model.PinyinBaseUnit; 27 | 28 | @SuppressLint("DefaultLocale") 29 | public class PinyinUtil { 30 | // init Pinyin Output Format 31 | private static HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); 32 | 33 | /** 34 | * Convert from Chinese string to a series of PinyinUnit 35 | * 36 | * @param chineseString 37 | * @param pinyinUnit 38 | */ 39 | public static void chineseStringToPinyinUnit(String chineseString,List pinyinUnit) { 40 | if ((null == chineseString) || (null == pinyinUnit)) { 41 | return; 42 | } 43 | 44 | String chineseStr = chineseString.toLowerCase(); 45 | 46 | if (null == format) { 47 | format = new HanyuPinyinOutputFormat(); 48 | } 49 | 50 | format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); 51 | 52 | int chineseStringLength = chineseStr.length(); 53 | StringBuffer nonPinyinString = new StringBuffer(); 54 | PinyinUnit pyUnit = null; 55 | String originalString = null; 56 | String[] pinyinStr = null; 57 | boolean lastChineseCharacters = true; 58 | int startPosition = -1; 59 | 60 | for (int i = 0; i < chineseStringLength; i++) { 61 | char ch = chineseStr.charAt(i); 62 | try { 63 | pinyinStr = PinyinHelper.toHanyuPinyinStringArray(ch, format); 64 | } catch (BadHanyuPinyinOutputFormatCombination e) { 65 | 66 | e.printStackTrace(); 67 | } 68 | 69 | if (null == pinyinStr) { 70 | if (true == lastChineseCharacters) { 71 | pyUnit = new PinyinUnit(); 72 | lastChineseCharacters = false; 73 | startPosition = i; 74 | nonPinyinString.delete(0, nonPinyinString.length()); 75 | } 76 | nonPinyinString.append(ch); 77 | } else { 78 | if (false == lastChineseCharacters) { 79 | // add continuous non-kanji characters to PinyinUnit 80 | originalString = nonPinyinString.toString(); 81 | String[] str = { nonPinyinString.toString() }; 82 | addPinyinUnit(pinyinUnit, pyUnit, false, originalString,str, startPosition); 83 | nonPinyinString.delete(0, nonPinyinString.length()); 84 | lastChineseCharacters = true; 85 | } 86 | // add single Chinese characters Pinyin(include Multiple Pinyin) 87 | // to PinyinUnit 88 | pyUnit = new PinyinUnit(); 89 | startPosition = i; 90 | originalString = String.valueOf(ch); 91 | addPinyinUnit(pinyinUnit, pyUnit, true, originalString,pinyinStr, startPosition); 92 | 93 | } 94 | } 95 | 96 | if (false == lastChineseCharacters) { 97 | // add continuous non-kanji characters to PinyinUnit 98 | originalString = nonPinyinString.toString(); 99 | String[] str = { nonPinyinString.toString() }; 100 | addPinyinUnit(pinyinUnit, pyUnit, false, originalString, str,startPosition); 101 | nonPinyinString.delete(0, nonPinyinString.length()); 102 | lastChineseCharacters = true; 103 | } 104 | 105 | } 106 | 107 | /** 108 | * get the first letter from original string 109 | * 110 | * @param pinyinUnit 111 | * @return return the first letter of original string,otherwise return null. 112 | */ 113 | public static String getFirstLetter(List pinyinUnit) { 114 | do { 115 | if (null == pinyinUnit || pinyinUnit.size() <= 0) { 116 | break; 117 | } 118 | 119 | List pinyinBaseUnit = pinyinUnit.get(0).getPinyinBaseUnitIndex(); 120 | if (null == pinyinBaseUnit || pinyinBaseUnit.size() <= 0) { 121 | break; 122 | } 123 | 124 | String pinyin = pinyinBaseUnit.get(0).getPinyin(); 125 | if (null == pinyin || pinyin.length() <= 0) { 126 | break; 127 | } 128 | 129 | return String.valueOf(pinyin.charAt(0)); 130 | 131 | } while (false); 132 | 133 | return null; 134 | } 135 | 136 | /** 137 | * get the first character from original string 138 | * 139 | * @param pinyinUnit 140 | * @return return the first character of original string,otherwise return 141 | * null. 142 | */ 143 | public static String getFirstCharacter(List pinyinUnit) { 144 | do { 145 | if (null == pinyinUnit || pinyinUnit.size() <= 0) { 146 | break; 147 | } 148 | 149 | List pinyinBaseUnit = pinyinUnit.get(0).getPinyinBaseUnitIndex(); 150 | if (null == pinyinBaseUnit || pinyinBaseUnit.size() <= 0) { 151 | break; 152 | } 153 | 154 | String originalString = pinyinBaseUnit.get(0).getOriginalString(); 155 | if (null == originalString || originalString.length() <= 0) { 156 | break; 157 | } 158 | 159 | return String.valueOf(originalString.charAt(0)); 160 | 161 | } while (false); 162 | 163 | return null; 164 | } 165 | 166 | /** 167 | * get sort key, as sort keyword 168 | * @param pinyinUnit 169 | * @return return sort key,otherwise return null. 170 | */ 171 | public static String getSortKey(List pinyinUnit) { 172 | StringBuffer sortKeyBuffer=new StringBuffer(); 173 | sortKeyBuffer.delete(0, sortKeyBuffer.length()); 174 | String splitSymbol=" "; 175 | do { 176 | if ((null == pinyinUnit) || (pinyinUnit.size() <= 0)) { 177 | break; 178 | } 179 | 180 | for(PinyinUnit pu:pinyinUnit){ 181 | if(pu.isPinyin()){ 182 | sortKeyBuffer.append(pu.getPinyinBaseUnitIndex().get(0).getPinyin()).append(splitSymbol); 183 | sortKeyBuffer.append(pu.getPinyinBaseUnitIndex().get(0).getOriginalString()).append(splitSymbol); 184 | }else{ 185 | sortKeyBuffer.append(pu.getPinyinBaseUnitIndex().get(0).getOriginalString()).append(splitSymbol); 186 | } 187 | } 188 | 189 | return sortKeyBuffer.toString(); 190 | } while (false); 191 | 192 | return null; 193 | } 194 | 195 | /** 196 | * judge chr is kanji 197 | * @param chr 198 | * @return Is kanji return true,otherwise return false. 199 | */ 200 | public static boolean isKanji(char chr){ 201 | String[] pinyinStr = null; 202 | try { 203 | pinyinStr = PinyinHelper.toHanyuPinyinStringArray(chr, format); 204 | } catch (BadHanyuPinyinOutputFormatCombination e) { 205 | e.printStackTrace(); 206 | } 207 | 208 | return (null==pinyinStr)?(false):(true); 209 | } 210 | 211 | private static void addPinyinUnit(List pinyinUnit,PinyinUnit pyUnit, boolean pinyin, String originalString,String[] string, int startPosition) { 212 | if ((null == pinyinUnit) || (null == pyUnit) 213 | || (null == originalString) || (null == string)) { 214 | return; 215 | } 216 | 217 | initPinyinUnit(pyUnit, pinyin, originalString, string, startPosition); 218 | pinyinUnit.add(pyUnit); 219 | 220 | return; 221 | 222 | } 223 | 224 | private static void initPinyinUnit(PinyinUnit pinyinUnit, boolean pinyin,String originalString, String[] string, int startPosition) { 225 | if ((null == pinyinUnit) || (null == originalString) 226 | || (null == string)) { 227 | return; 228 | } 229 | int i = 0; 230 | int j = 0; 231 | int k = 0; 232 | int strLength = string.length; 233 | pinyinUnit.setPinyin(pinyin); 234 | pinyinUnit.setStartPosition(startPosition); 235 | 236 | PinyinBaseUnit pinyinBaseUnit = null; 237 | 238 | if (false == pinyin || strLength <= 1) {// no more than one pinyin 239 | for (i = 0; i < strLength; i++) { 240 | pinyinBaseUnit = new PinyinBaseUnit(); 241 | initPinyinBaseUnit(pinyinBaseUnit, originalString, string[i]); 242 | pinyinUnit.getPinyinBaseUnitIndex().add(pinyinBaseUnit); 243 | } 244 | } else { // more than one pinyin.//we must delete the same pinyin 245 | // string,because pinyin without tone. 246 | 247 | pinyinBaseUnit = new PinyinBaseUnit(); 248 | initPinyinBaseUnit(pinyinBaseUnit, originalString, string[0]); 249 | pinyinUnit.getPinyinBaseUnitIndex().add(pinyinBaseUnit); 250 | for (j = 1; j < strLength; j++) { 251 | int curStringIndexlength = pinyinUnit.getPinyinBaseUnitIndex().size(); 252 | for (k = 0; k < curStringIndexlength; k++) { 253 | if (pinyinUnit.getPinyinBaseUnitIndex().get(k).getPinyin().equals(string[j])) { 254 | break; 255 | } 256 | } 257 | 258 | if (k == curStringIndexlength) { 259 | pinyinBaseUnit = new PinyinBaseUnit(); 260 | initPinyinBaseUnit(pinyinBaseUnit, originalString, string[j]); 261 | pinyinUnit.getPinyinBaseUnitIndex().add(pinyinBaseUnit); 262 | } 263 | } 264 | } 265 | } 266 | 267 | private static void initPinyinBaseUnit(PinyinBaseUnit pinyinBaseUnit,String originalString, String pinyin) { 268 | if ((null == pinyinBaseUnit) || (null == originalString) 269 | || (null == pinyin)) { 270 | return; 271 | } 272 | 273 | pinyinBaseUnit.setOriginalString(new String(originalString)); 274 | pinyinBaseUnit.setPinyin(new String(pinyin)); 275 | int pinyinLength = pinyin.length(); 276 | StringBuffer numBuffer = new StringBuffer(); 277 | numBuffer.delete(0, numBuffer.length()); 278 | 279 | for (int i = 0; i < pinyinLength; i++) { 280 | char ch = T9Util.getT9Number(pinyin.charAt(i)); 281 | numBuffer.append(ch); 282 | } 283 | 284 | pinyinBaseUnit.setNumber(new String(numBuffer.toString())); 285 | numBuffer.delete(0, numBuffer.length()); 286 | 287 | return; 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /PinyinSearch/src/com/pinyinsearch/util/QwertyMatchPinyinUnits.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 handsomezhou 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pinyinsearch.util; 18 | 19 | import java.util.List; 20 | import android.annotation.SuppressLint; 21 | import com.pinyinsearch.model.PinyinBaseUnit; 22 | import com.pinyinsearch.model.PinyinUnit; 23 | 24 | @SuppressLint("DefaultLocale") 25 | public class QwertyMatchPinyinUnits { 26 | // private static final String TAG="QwertyMatchPinyinUnits"; 27 | /** 28 | * Match Pinyin Units 29 | * @param pinyinUnits 30 | * @param baseData the original string which be parsed to PinyinUnit 31 | * @param search search key words 32 | * @param chineseKeyWord the sub string of base data 33 | * @return true if match success,false otherwise. 34 | */ 35 | @SuppressLint("DefaultLocale") 36 | public static boolean matchPinyinUnits(final List pinyinUnits, 37 | final String baseData, String search, StringBuffer chineseKeyWord) { 38 | if ((null == pinyinUnits) || (null == search) 39 | || (null == chineseKeyWord)) { 40 | return false; 41 | } 42 | 43 | StringBuffer matchSearch = new StringBuffer(); 44 | matchSearch.delete(0, matchSearch.length()); 45 | chineseKeyWord.delete(0, chineseKeyWord.length()); 46 | 47 | //search by original string 48 | String searchLowerCase=search.toLowerCase(); 49 | int index=baseData.toLowerCase().indexOf(searchLowerCase); 50 | if(index>-1){ 51 | chineseKeyWord.append(baseData.substring(index, index+searchLowerCase.length())); 52 | return true; 53 | } 54 | 55 | //search by pinyin characters 56 | int pinyinUnitsLength = pinyinUnits.size(); 57 | StringBuffer searchBuffer = new StringBuffer(); 58 | for (int i = 0; i < pinyinUnitsLength; i++) { 59 | int j = 0; 60 | chineseKeyWord.delete(0, chineseKeyWord.length()); 61 | searchBuffer.delete(0, searchBuffer.length()); 62 | searchBuffer.append(searchLowerCase); 63 | boolean found = findPinyinUnits(pinyinUnits, i, j, baseData,searchBuffer, chineseKeyWord); 64 | if (true == found) { 65 | return true; 66 | } 67 | } 68 | 69 | return false; 70 | } 71 | 72 | /** 73 | * @description match search string with pinyinUnits,if success,save the Chinese keywords. 74 | * @param pinyinUnits pinyinUnits head node index 75 | * @param pinyinUnitIndex pinyinUint Index 76 | * @param qwertyPinyinUnitIndex pinyinBaseUnit Index 77 | * @param baseData base data for search. 78 | * @param searchBuffer search keyword. 79 | * @param chineseKeyWord save the Chinese keyword. 80 | * @return true if find,false otherwise. 81 | */ 82 | private static boolean findPinyinUnits(final List pinyinUnits, 83 | int pinyinUnitIndex, int qwertyPinyinUnitIndex, final String baseData, 84 | StringBuffer searchBuffer, StringBuffer chineseKeyWord) { 85 | if ((null == pinyinUnits)||(null == baseData)||(null == searchBuffer)||(null == chineseKeyWord)) { 86 | return false; 87 | } 88 | 89 | String search = searchBuffer.toString(); 90 | if (search.length() <= 0) { // match success 91 | return true; 92 | } 93 | 94 | if (pinyinUnitIndex >= pinyinUnits.size()) { 95 | return false; 96 | } 97 | PinyinUnit pyUnit = pinyinUnits.get(pinyinUnitIndex); 98 | 99 | if (qwertyPinyinUnitIndex >= pyUnit.getPinyinBaseUnitIndex().size()) { 100 | return false; 101 | } 102 | 103 | PinyinBaseUnit pinyinBaseUnit = pyUnit.getPinyinBaseUnitIndex().get(qwertyPinyinUnitIndex); 104 | 105 | if (pyUnit.isPinyin()) { 106 | 107 | if (search.startsWith(String.valueOf(pinyinBaseUnit.getPinyin().charAt(0)))) {// match pinyin first character 108 | searchBuffer.delete(0, 1);// delete the match character 109 | chineseKeyWord.append(baseData.charAt(pyUnit.getStartPosition())); 110 | boolean found = findPinyinUnits(pinyinUnits,pinyinUnitIndex + 1, 0, baseData, searchBuffer,chineseKeyWord); 111 | if (true == found) { 112 | return true; 113 | } else { 114 | searchBuffer.insert(0, pinyinBaseUnit.getPinyin().charAt(0)); 115 | chineseKeyWord.deleteCharAt(chineseKeyWord.length() - 1); 116 | } 117 | 118 | } 119 | 120 | if (pinyinBaseUnit.getPinyin().startsWith(search)) { 121 | // The string of "search" is the string of pinyinBaseUnit.getPinyin() of a subset. means match success. 122 | chineseKeyWord.append(baseData.charAt(pyUnit.getStartPosition())); 123 | searchBuffer.delete(0, searchBuffer.length()); 124 | return true; 125 | 126 | } else if (search.startsWith(pinyinBaseUnit.getPinyin())) { // match quanpin success 127 | // The string of pinyinBaseUnit.getPinyin() is the string of "search" of a subset. 128 | searchBuffer.delete(0, pinyinBaseUnit.getPinyin().length()); 129 | chineseKeyWord.append(baseData.charAt(pyUnit.getStartPosition())); 130 | boolean found = findPinyinUnits(pinyinUnits,pinyinUnitIndex+1, 0, baseData, searchBuffer,chineseKeyWord); 131 | if (true == found) { 132 | return true; 133 | } else { 134 | searchBuffer.insert(0, pinyinBaseUnit.getPinyin()); 135 | chineseKeyWord.deleteCharAt(chineseKeyWord.length()-1); 136 | } 137 | } else { // mismatch 138 | boolean found = findPinyinUnits(pinyinUnits, pinyinUnitIndex,qwertyPinyinUnitIndex+1, baseData, searchBuffer,chineseKeyWord); 139 | if (found == true) { 140 | return true; 141 | } 142 | } 143 | 144 | } else { // non-pure Pinyin 145 | if (pinyinBaseUnit.getPinyin().startsWith(search)) { 146 | // The string of "search" is the string of pinyinBaseUnit.getPinyin() of a subset. 147 | int startIndex = 0; 148 | chineseKeyWord.append(baseData.substring(startIndex+pyUnit.getStartPosition(), startIndex+pyUnit.getStartPosition() + search.length())); 149 | searchBuffer.delete(0, searchBuffer.length()); 150 | return true; 151 | } else if (search.startsWith(pinyinBaseUnit.getPinyin())) { // match all non-pure pinyin 152 | // The string of pinyinBaseUnit.getPinyin() is the string of "search" of a subset. 153 | int startIndex = 0; 154 | searchBuffer.delete(0, pinyinBaseUnit.getPinyin().length()); 155 | chineseKeyWord.append(baseData.substring(startIndex+pyUnit.getStartPosition(),startIndex+pyUnit.getStartPosition()+pinyinBaseUnit.getPinyin().length())); 156 | boolean found = findPinyinUnits(pinyinUnits,pinyinUnitIndex+1, 0, baseData, searchBuffer,chineseKeyWord); 157 | if (true == found) { 158 | return true; 159 | } else { 160 | searchBuffer.insert(0, pinyinBaseUnit.getPinyin()); 161 | chineseKeyWord.delete(chineseKeyWord.length()-pinyinBaseUnit.getPinyin().length(),chineseKeyWord.length()); 162 | } 163 | } else if ((chineseKeyWord.length() <= 0)) { 164 | if (pinyinBaseUnit.getPinyin().contains(search)) { 165 | int index = pinyinBaseUnit.getPinyin().indexOf(search); 166 | chineseKeyWord.append(baseData.substring(index+pyUnit.getStartPosition(),index+pyUnit.getStartPosition()+search.length())); 167 | searchBuffer.delete(0, searchBuffer.length()); 168 | return true; 169 | } else { 170 | // match case:[Non-Chinese characters]+[Chinese characters] 171 | // for example:baseData="Tony测试"; match this case:"onycs" 172 | // start [Non-Chinese characters]+[Chinese characters] 173 | int numLength = pinyinBaseUnit.getPinyin().length(); 174 | for (int i = 0; i < numLength; i++) { 175 | String subStr = pinyinBaseUnit.getPinyin().substring(i); 176 | if (search.startsWith(subStr)) { 177 | searchBuffer.delete(0, subStr.length()); 178 | chineseKeyWord.append(baseData.substring(i+pyUnit.getStartPosition(),i+pyUnit.getStartPosition()+subStr.length())); 179 | boolean found = findPinyinUnits(pinyinUnits,pinyinUnitIndex+1, 0, baseData,searchBuffer, chineseKeyWord); 180 | if (true == found) { 181 | return true; 182 | } else { 183 | searchBuffer.insert(0, pinyinBaseUnit.getPinyin().substring(i)); 184 | chineseKeyWord.delete(chineseKeyWord.length()-subStr.length(),chineseKeyWord.length()); 185 | } 186 | 187 | } 188 | } 189 | // end [Non-Chinese characters]+[Chinese characters] 190 | 191 | // in fact,if pyUnit.isPinyin()==false, pyUnit.getQwertyPinyinUnitIndex().size()==1. The function of findPinyinUnits() will return false. 192 | boolean found = findPinyinUnits(pinyinUnits,pinyinUnitIndex, qwertyPinyinUnitIndex + 1, baseData,searchBuffer, chineseKeyWord); 193 | if (true == found) { 194 | return true; 195 | } 196 | } 197 | } else { // mismatch 198 | // in fact,if pyUnit.isPinyin()==false, pyUnit.getQwertyPinyinUnitIndex().size()==1. The function of findPinyinUnits() will return false. 199 | boolean found = findPinyinUnits(pinyinUnits, pinyinUnitIndex,qwertyPinyinUnitIndex+1, baseData, searchBuffer,chineseKeyWord); 200 | if (true == found) { 201 | return true; 202 | } 203 | } 204 | } 205 | return false; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /PinyinSearch/src/com/pinyinsearch/util/T9MatchPinyinUnits.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 handsomezhou 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.pinyinsearch.util; 18 | 19 | import java.util.List; 20 | 21 | import com.pinyinsearch.model.PinyinUnit; 22 | import com.pinyinsearch.model.PinyinBaseUnit; 23 | 24 | public class T9MatchPinyinUnits { 25 | //private static final String TAG="T9MatchPinyinUnits"; 26 | /** 27 | * Match Pinyin Units 28 | * @param pinyinUnits 29 | * @param baseData the original string which be parsed to PinyinUnit 30 | * @param search search key words 31 | * @param chineseKeyWord the sub string of base data 32 | * @return true if match success,false otherwise. 33 | */ 34 | public static boolean matchPinyinUnits(final List pinyinUnits,final String baseData, String search,StringBuffer chineseKeyWord){ 35 | if((null==pinyinUnits)||(null==search)||(null==chineseKeyWord)){ 36 | return false; 37 | } 38 | 39 | StringBuffer matchSearch=new StringBuffer(); 40 | matchSearch.delete(0, matchSearch.length()); 41 | chineseKeyWord.delete(0, chineseKeyWord.length()); 42 | //PinyinUnit pyUnit=null; 43 | 44 | int pinyinUnitsLength=0; 45 | pinyinUnitsLength=pinyinUnits.size(); 46 | StringBuffer searchBuffer=new StringBuffer(); 47 | for(int i=0; i pinyinUnits,int pinyinUnitIndex,int t9PinyinUnitIndex,final String baseData, StringBuffer searchBuffer,StringBuffer chineseKeyWord ){ 77 | if((null==pinyinUnits)||(null==baseData)||(null==searchBuffer)||(null==chineseKeyWord)){ 78 | return false; 79 | } 80 | 81 | String search=searchBuffer.toString(); 82 | if(search.length()<=0){ //match success 83 | return true; 84 | } 85 | 86 | if(pinyinUnitIndex>=pinyinUnits.size()){ 87 | return false; 88 | } 89 | PinyinUnit pyUnit=pinyinUnits.get(pinyinUnitIndex); 90 | 91 | if(t9PinyinUnitIndex>=pyUnit.getPinyinBaseUnitIndex().size()){ 92 | return false; 93 | } 94 | 95 | PinyinBaseUnit pinyinBaseUnit=pyUnit.getPinyinBaseUnitIndex().get(t9PinyinUnitIndex); 96 | 97 | 98 | 99 | if(pyUnit.isPinyin()){ 100 | 101 | if(search.startsWith(String.valueOf(pinyinBaseUnit.getNumber().charAt(0)))){// match pinyin first character 102 | searchBuffer.delete(0,1);//delete the match character 103 | chineseKeyWord.append(baseData.charAt(pyUnit.getStartPosition())); 104 | boolean found=findPinyinUnits(pinyinUnits, pinyinUnitIndex+1, 0, baseData, searchBuffer, chineseKeyWord); 105 | if(true==found){ 106 | return true; 107 | }else{ 108 | searchBuffer.insert(0, pinyinBaseUnit.getNumber().charAt(0)); 109 | chineseKeyWord.deleteCharAt(chineseKeyWord.length()-1); 110 | } 111 | 112 | } 113 | 114 | if(pinyinBaseUnit.getNumber().startsWith(search)){ 115 | //The string of "search" is the string of t9PinyinUnit.getNumber() of a subset. means match success. 116 | chineseKeyWord.append(baseData.charAt(pyUnit.getStartPosition())); 117 | searchBuffer.delete(0, searchBuffer.length()); 118 | return true; 119 | 120 | }else if(search.startsWith(pinyinBaseUnit.getNumber())){ //match quanpin success 121 | //The string of t9PinyinUnit.getNumber() is the string of "search" of a subset. 122 | searchBuffer.delete(0, pinyinBaseUnit.getNumber().length()); 123 | chineseKeyWord.append(baseData.charAt(pyUnit.getStartPosition())); 124 | boolean found=findPinyinUnits(pinyinUnits, pinyinUnitIndex+1, 0, baseData, searchBuffer, chineseKeyWord); 125 | if(true==found){ 126 | return true; 127 | }else{ 128 | searchBuffer.insert(0, pinyinBaseUnit.getNumber()); 129 | chineseKeyWord.deleteCharAt(chineseKeyWord.length()-1); 130 | } 131 | }else{ //mismatch 132 | boolean found=findPinyinUnits(pinyinUnits, pinyinUnitIndex, t9PinyinUnitIndex+1, baseData, searchBuffer, chineseKeyWord); 133 | if(found==true){ 134 | return true; 135 | } 136 | } 137 | 138 | }else{ //non-pure Pinyin 139 | 140 | if(pinyinBaseUnit.getNumber().startsWith(search)){ 141 | //The string of "search" is the string of t9PinyinUnit.getNumber() of a subset. 142 | int startIndex=0; 143 | chineseKeyWord.append(baseData.substring(startIndex+pyUnit.getStartPosition(),startIndex+pyUnit.getStartPosition()+ search.length())); 144 | searchBuffer.delete(0, searchBuffer.length()); 145 | return true; 146 | }else if(search.startsWith(pinyinBaseUnit.getNumber())){ //match all non-pure pinyin 147 | //The string of t9PinyinUnit.getNumber() is the string of "search" of a subset. 148 | int startIndex=0; 149 | searchBuffer.delete(0, pinyinBaseUnit.getNumber().length()); 150 | chineseKeyWord.append(baseData.substring(startIndex+pyUnit.getStartPosition(),startIndex+pyUnit.getStartPosition()+ pinyinBaseUnit.getNumber().length())); 151 | boolean found=findPinyinUnits(pinyinUnits, pinyinUnitIndex+1, 0, baseData, searchBuffer, chineseKeyWord); 152 | if(true==found){ 153 | return true; 154 | }else{ 155 | searchBuffer.insert(0, pinyinBaseUnit.getNumber()); 156 | chineseKeyWord.delete(chineseKeyWord.length()-pinyinBaseUnit.getNumber().length(), chineseKeyWord.length()); 157 | } 158 | }else if((chineseKeyWord.length()<=0)){ 159 | if(pinyinBaseUnit.getNumber().contains(search)){ 160 | int index=pinyinBaseUnit.getNumber().indexOf(search); 161 | chineseKeyWord.append(baseData.substring(index+pyUnit.getStartPosition(),index+pyUnit.getStartPosition()+ search.length())); 162 | searchBuffer.delete(0, searchBuffer.length()); 163 | return true; 164 | }else{ 165 | // match case:[Non-Chinese characters]+[Chinese characters] 166 | //for example:baseData="Tony测试"; match this case:"onycs"<===>"66927" 167 | //start [Non-Chinese characters]+[Chinese characters] 168 | int numLength=pinyinBaseUnit.getNumber().length(); 169 | for(int i=0; i 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /libs/BaiduLBS_Android.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/libs/BaiduLBS_Android.jar -------------------------------------------------------------------------------- /libs/armeabi-v7a/libBaiduMapSDK_v3_4_0_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/libs/armeabi-v7a/libBaiduMapSDK_v3_4_0_15.so -------------------------------------------------------------------------------- /libs/armeabi-v7a/liblocSDK5.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/libs/armeabi-v7a/liblocSDK5.so -------------------------------------------------------------------------------- /libs/armeabi/libBaiduMapSDK_v3_4_0_15.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/libs/armeabi/libBaiduMapSDK_v3_4_0_15.so -------------------------------------------------------------------------------- /libs/armeabi/liblocSDK5.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/libs/armeabi/liblocSDK5.so -------------------------------------------------------------------------------- /project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by IntelliJ IDEA 2 | # Project target. 3 | android.library.reference.1=PinyinSearch 4 | target=android-20 5 | -------------------------------------------------------------------------------- /res/anim/city_locating_anim.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/anim/publicloading.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /res/color/wb_title_text_color_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/drawable-hdpi/btn_choose_city_normal.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/btn_choose_city_normal.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/city_locate_failed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/city_locate_failed.png -------------------------------------------------------------------------------- /res/drawable-hdpi/city_locate_success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/city_locate_success.png -------------------------------------------------------------------------------- /res/drawable-hdpi/city_locating_frame1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/city_locating_frame1.png -------------------------------------------------------------------------------- /res/drawable-hdpi/city_locating_frame2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/city_locating_frame2.png -------------------------------------------------------------------------------- /res/drawable-hdpi/city_locating_frame3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/city_locating_frame3.png -------------------------------------------------------------------------------- /res/drawable-hdpi/city_switch_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/city_switch_pressed.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/common_alert_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/common_alert_bg.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/publicloading1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/publicloading1.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_btn_off_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_btn_off_normal.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_btn_off_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_btn_off_pressed.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_letter_search_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_letter_search_normal.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_list_search_enabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_list_search_enabled.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_list_search_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_list_search_icon.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_list_search_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_list_search_pressed.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_title_change_map_disenabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_title_change_map_disenabled.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_title_change_map_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_title_change_map_normal.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_title_change_map_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_title_change_map_pressed.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_title_drawable.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_title_drawable.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/wb_title_search_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-hdpi/wb_title_search_disabled.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/bg_shop_search.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/bg_shop_search.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/bookingdetail_public_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/bookingdetail_public_close.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_gray_delete_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/btn_gray_delete_sel.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_gray_delete_unsel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/btn_gray_delete_unsel.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_search_sel.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/btn_search_sel.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/btn_search_unsel.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/btn_search_unsel.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/empty_page_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/empty_page_search.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_back_u.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/ic_back_u.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/icon_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/icon_search.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/topbar_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/topbar_bg.9.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_back_btn_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_back_btn_normal.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_back_btn_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_back_btn_pressed.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_btn_off_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_btn_off_normal.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_btn_off_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_btn_off_pressed.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_list_search_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_list_search_icon.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_list_search_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_list_search_pressed.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_title_change_map_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_title_change_map_normal.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_title_change_map_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_title_change_map_pressed.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_title_map_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_title_map_disabled.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/wb_title_search_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable-xhdpi/wb_title_search_disabled.png -------------------------------------------------------------------------------- /res/drawable/btn_gray_delete_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/drawable/btn_search_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/drawable/city_hot_grid_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/drawable/city_item_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /res/drawable/city_search_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /res/drawable/clickable_white_to_gray.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/drawable/icon.png -------------------------------------------------------------------------------- /res/drawable/wb_back_btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /res/drawable/wb_btn_off.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /res/drawable/wb_change_city_click.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/drawable/wb_list_search_btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/drawable/wb_title_change_map_btn.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /res/layout/bookname_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /res/layout/city_change_dailog.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 11 | 14 | 17 | 18 | 20 | 22 | 24 | 29 | 34 | 35 | 36 | 37 | 39 | 41 | 44 |