├── contact.png ├── bin ├── classes.dex ├── resources.ap_ ├── 省份选择器A-Z.apk ├── 通讯录选择器A-Z.apk ├── res │ └── crunch │ │ ├── drawable-hdpi │ │ ├── ic_launcher.png │ │ ├── sorlistview_show_head_toast_bg.9.PNG │ │ ├── sorlistview_search_bar_icon_normal.png │ │ └── sorlistview_emotionstore_progresscancelbtn.png │ │ ├── drawable-mdpi │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ │ └── drawable-xxhdpi │ │ └── ic_launcher.png ├── classes │ └── com │ │ └── example │ │ └── provinceselector │ │ ├── R.class │ │ ├── R$id.class │ │ ├── R$array.class │ │ ├── R$attr.class │ │ ├── R$dimen.class │ │ ├── R$layout.class │ │ ├── R$menu.class │ │ ├── R$string.class │ │ ├── R$style.class │ │ ├── SideBar.class │ │ ├── R$drawable.class │ │ ├── SortModel.class │ │ ├── BuildConfig.class │ │ ├── ClearEditText.class │ │ ├── MainActivity.class │ │ ├── SortAdapter.class │ │ ├── CharacterParser.class │ │ ├── MainActivity$1.class │ │ ├── MainActivity$2.class │ │ ├── MainActivity$3.class │ │ ├── PinyinComparator.class │ │ ├── SortAdapter$ViewHolder.class │ │ └── SideBar$OnTouchingLetterChangedListener.class ├── jarlist.cache ├── dexedLibs │ ├── android-support-v4-5b8a3cb5d193a9c1ccc75bd9befd16a7.jar │ └── android-support-v4-954a3e8d7841b6b0394254377019d6c5.jar └── AndroidManifest.xml ├── ic_launcher-web.png ├── .settings ├── org.eclipse.core.resources.prefs └── org.eclipse.jdt.core.prefs ├── libs └── android-support-v4.jar ├── res ├── drawable-hdpi │ ├── ic_launcher.png │ ├── sorlistview_show_head_toast_bg.9.PNG │ ├── sorlistview_search_bar_icon_normal.png │ ├── sorlistview_search_bar_edit_normal.9.png │ ├── sorlistview_search_bar_edit_pressed.9.png │ └── sorlistview_emotionstore_progresscancelbtn.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── values-sw600dp │ └── dimens.xml ├── values │ ├── dimens.xml │ ├── strings.xml │ ├── styles.xml │ └── arrays.xml ├── menu │ └── main.xml ├── values-sw720dp-land │ └── dimens.xml ├── values-v11 │ └── styles.xml ├── values-v14 │ └── styles.xml ├── drawable │ ├── sorlistview_search_bar_edit_selector.xml │ └── sortlistview_sidebar_background.xml └── layout │ ├── item_sort_listview.xml │ └── activity_listview_sort_main.xml ├── gen └── com │ └── example │ └── provinceselector │ ├── BuildConfig.java │ └── R.java ├── README.md ├── .classpath ├── src └── com │ └── example │ └── provinceselector │ ├── SortModel.java │ ├── PinyinComparator.java │ ├── SortAdapter.java │ ├── SideBar.java │ ├── ClearEditText.java │ ├── MainActivity.java │ └── CharacterParser.java ├── .gitattributes ├── project.properties ├── .gitignore ├── proguard-project.txt ├── .project └── AndroidManifest.xml /contact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/contact.png -------------------------------------------------------------------------------- /bin/classes.dex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes.dex -------------------------------------------------------------------------------- /bin/resources.ap_: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/resources.ap_ -------------------------------------------------------------------------------- /bin/省份选择器A-Z.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/省份选择器A-Z.apk -------------------------------------------------------------------------------- /bin/通讯录选择器A-Z.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/通讯录选择器A-Z.apk -------------------------------------------------------------------------------- /ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/ic_launcher-web.png -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/libs/android-support-v4.jar -------------------------------------------------------------------------------- /res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/crunch/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/crunch/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/crunch/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/res/crunch/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R.class -------------------------------------------------------------------------------- /bin/jarlist.cache: -------------------------------------------------------------------------------- 1 | # cache for current jar dependency. DO NOT EDIT. 2 | # format is 3 | # Encoding is UTF-8 4 | -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$id.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$id.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$array.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$array.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$attr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$attr.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$dimen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$dimen.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$layout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$layout.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$menu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$menu.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$string.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$string.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$style.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$style.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/SideBar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/SideBar.class -------------------------------------------------------------------------------- /res/drawable-hdpi/sorlistview_show_head_toast_bg.9.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-hdpi/sorlistview_show_head_toast_bg.9.PNG -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/R$drawable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/R$drawable.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/SortModel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/SortModel.class -------------------------------------------------------------------------------- /res/drawable-hdpi/sorlistview_search_bar_icon_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-hdpi/sorlistview_search_bar_icon_normal.png -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/BuildConfig.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/ClearEditText.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/ClearEditText.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/MainActivity.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/MainActivity.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/SortAdapter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/SortAdapter.class -------------------------------------------------------------------------------- /res/drawable-hdpi/sorlistview_search_bar_edit_normal.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-hdpi/sorlistview_search_bar_edit_normal.9.png -------------------------------------------------------------------------------- /res/drawable-hdpi/sorlistview_search_bar_edit_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-hdpi/sorlistview_search_bar_edit_pressed.9.png -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/CharacterParser.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/CharacterParser.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/MainActivity$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/MainActivity$1.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/MainActivity$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/MainActivity$2.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/MainActivity$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/MainActivity$3.class -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/PinyinComparator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/PinyinComparator.class -------------------------------------------------------------------------------- /bin/res/crunch/drawable-hdpi/sorlistview_show_head_toast_bg.9.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-hdpi/sorlistview_show_head_toast_bg.9.PNG -------------------------------------------------------------------------------- /res/drawable-hdpi/sorlistview_emotionstore_progresscancelbtn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/res/drawable-hdpi/sorlistview_emotionstore_progresscancelbtn.png -------------------------------------------------------------------------------- /bin/res/crunch/drawable-hdpi/sorlistview_search_bar_icon_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-hdpi/sorlistview_search_bar_icon_normal.png -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/SortAdapter$ViewHolder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/SortAdapter$ViewHolder.class -------------------------------------------------------------------------------- /bin/dexedLibs/android-support-v4-5b8a3cb5d193a9c1ccc75bd9befd16a7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/dexedLibs/android-support-v4-5b8a3cb5d193a9c1ccc75bd9befd16a7.jar -------------------------------------------------------------------------------- /bin/dexedLibs/android-support-v4-954a3e8d7841b6b0394254377019d6c5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/dexedLibs/android-support-v4-954a3e8d7841b6b0394254377019d6c5.jar -------------------------------------------------------------------------------- /bin/res/crunch/drawable-hdpi/sorlistview_emotionstore_progresscancelbtn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/res/crunch/drawable-hdpi/sorlistview_emotionstore_progresscancelbtn.png -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /bin/classes/com/example/provinceselector/SideBar$OnTouchingLetterChangedListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichao315/Contact/HEAD/bin/classes/com/example/provinceselector/SideBar$OnTouchingLetterChangedListener.class -------------------------------------------------------------------------------- /gen/com/example/provinceselector/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.example.provinceselector; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Contact 2 | ======= 3 | 4 | 仿小米、华为、三星各大产商手机联系人、通讯录 5 | 6 | android原生的通讯录被各大产商废弃,纷纷开发出适合自己风格的联系人通讯录,例如我在这里针对中国手机产商小米手机做了一款通讯录App,该App小巧易于集成,提供自定义控件源码,修改方便! 7 | ![image](https://github.com/lichao315/Contact/blob/master/contact.png) 8 | -------------------------------------------------------------------------------- /res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 省份选择器A-Z 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /res/drawable/sorlistview_search_bar_edit_selector.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/com/example/provinceselector/SortModel.java: -------------------------------------------------------------------------------- 1 | package com.example.provinceselector; 2 | 3 | public class SortModel { 4 | 5 | private String name; // 显示的数据 6 | private String sortLetters; // 显示数据拼音的首字母 7 | 8 | public String getName() { 9 | return name; 10 | } 11 | 12 | public void setName(String name) { 13 | this.name = name; 14 | } 15 | 16 | public String getSortLetters() { 17 | return sortLetters; 18 | } 19 | 20 | public void setSortLetters(String sortLetters) { 21 | this.sortLetters = sortLetters; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /res/drawable/sortlistview_sidebar_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /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-19 15 | -------------------------------------------------------------------------------- /src/com/example/provinceselector/PinyinComparator.java: -------------------------------------------------------------------------------- 1 | package com.example.provinceselector; 2 | 3 | import java.util.Comparator; 4 | 5 | /** 6 | * 7 | * @author xiaanming 8 | * 9 | */ 10 | public class PinyinComparator implements Comparator { 11 | 12 | public int compare(SortModel o1, SortModel o2) { 13 | if (o1.getSortLetters().equals("@") 14 | || o2.getSortLetters().equals("#")) { 15 | return -1; 16 | } else if (o1.getSortLetters().equals("#") 17 | || o2.getSortLetters().equals("@")) { 18 | return 1; 19 | } else { 20 | return o1.getSortLetters().compareTo(o2.getSortLetters()); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must ends with two \r. 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | -------------------------------------------------------------------------------- /res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 21 | 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 通讯录选择器A-Z 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 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /bin/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /res/layout/item_sort_listview.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 19 | 20 | 32 | 33 | -------------------------------------------------------------------------------- /res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Peter 6 | Allen 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 | BOBO 43 | Jobs 44 | 动力火车 45 | 伍佰 46 | #蔡依林 47 | $797835344$ 48 | Jack 49 | ~夏先生 50 | 51 | 52 | -------------------------------------------------------------------------------- /res/layout/activity_listview_sort_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 17 | 18 | 21 | 22 | 28 | 29 | 39 | 40 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/com/example/provinceselector/SortAdapter.java: -------------------------------------------------------------------------------- 1 | package com.example.provinceselector; 2 | 3 | import java.util.List; 4 | 5 | import android.content.Context; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.BaseAdapter; 10 | import android.widget.SectionIndexer; 11 | import android.widget.TextView; 12 | 13 | public class SortAdapter extends BaseAdapter implements SectionIndexer { 14 | private List list = null; 15 | private Context mContext; 16 | 17 | public SortAdapter(Context mContext, List list) { 18 | this.mContext = mContext; 19 | this.list = list; 20 | } 21 | 22 | /** 23 | * 当ListView数据发生变化时,调用此方法来更新ListView 24 | * 25 | * @param list 26 | */ 27 | public void updateListView(List list) { 28 | this.list = list; 29 | notifyDataSetChanged(); 30 | } 31 | 32 | public int getCount() { 33 | return this.list.size(); 34 | } 35 | 36 | public Object getItem(int position) { 37 | return list.get(position); 38 | } 39 | 40 | public long getItemId(int position) { 41 | return position; 42 | } 43 | 44 | public View getView(final int position, View view, ViewGroup arg2) { 45 | ViewHolder viewHolder = null; 46 | final SortModel mContent = list.get(position); 47 | if (view == null) { 48 | viewHolder = new ViewHolder(); 49 | view = LayoutInflater.from(mContext).inflate(R.layout.item_sort_listview, null); 50 | viewHolder.tvTitle = (TextView) view.findViewById(R.id.title); 51 | viewHolder.tvLetter = (TextView) view.findViewById(R.id.catalog); 52 | view.setTag(viewHolder); 53 | } else { 54 | viewHolder = (ViewHolder) view.getTag(); 55 | } 56 | 57 | // 根据position获取分类的首字母的Char ascii值 58 | int section = getSectionForPosition(position); 59 | 60 | // 如果当前位置等于该分类首字母的Char的位置 ,则认为是第一次出现 61 | if (position == getPositionForSection(section)) { 62 | viewHolder.tvLetter.setVisibility(View.VISIBLE); 63 | viewHolder.tvLetter.setText(mContent.getSortLetters()); 64 | } else { 65 | viewHolder.tvLetter.setVisibility(View.GONE); 66 | } 67 | 68 | viewHolder.tvTitle.setText(this.list.get(position).getName()); 69 | 70 | return view; 71 | 72 | } 73 | 74 | final static class ViewHolder { 75 | TextView tvLetter; 76 | TextView tvTitle; 77 | } 78 | 79 | /** 80 | * 根据ListView的当前位置获取分类的首字母的Char ascii值 81 | */ 82 | public int getSectionForPosition(int position) { 83 | return list.get(position).getSortLetters().charAt(0); 84 | } 85 | 86 | /** 87 | * 根据分类的首字母的Char ascii值获取其第一次出现该首字母的位置 88 | */ 89 | public int getPositionForSection(int section) { 90 | for (int i = 0; i < getCount(); i++) { 91 | String sortStr = list.get(i).getSortLetters(); 92 | char firstChar = sortStr.toUpperCase().charAt(0); 93 | if (firstChar == section) { 94 | return i; 95 | } 96 | } 97 | 98 | return -1; 99 | } 100 | 101 | /** 102 | * 提取英文的首字母,非英文字母用#代替。 103 | * 104 | * @param str 105 | * @return 106 | */ 107 | private String getAlpha(String str) { 108 | String sortStr = str.trim().substring(0, 1).toUpperCase(); 109 | // 正则表达式,判断首字母是否是英文字母 110 | if (sortStr.matches("[A-Z]")) { 111 | return sortStr; 112 | } else { 113 | return "#"; 114 | } 115 | } 116 | 117 | @Override 118 | public Object[] getSections() { 119 | return null; 120 | } 121 | } -------------------------------------------------------------------------------- /gen/com/example/provinceselector/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package com.example.provinceselector; 9 | 10 | public final class R { 11 | public static final class array { 12 | public static final int date=0x7f040000; 13 | } 14 | public static final class attr { 15 | } 16 | public static final class dimen { 17 | /** Default screen margins, per the Android Design guidelines. 18 | 19 | Customize dimensions originally defined in res/values/dimens.xml (such as 20 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. 21 | 22 | */ 23 | public static final int activity_horizontal_margin=0x7f050000; 24 | public static final int activity_vertical_margin=0x7f050001; 25 | } 26 | public static final class drawable { 27 | public static final int ic_launcher=0x7f020000; 28 | public static final int sorlistview_emotionstore_progresscancelbtn=0x7f020001; 29 | public static final int sorlistview_search_bar_edit_normal=0x7f020002; 30 | public static final int sorlistview_search_bar_edit_pressed=0x7f020003; 31 | public static final int sorlistview_search_bar_edit_selector=0x7f020004; 32 | public static final int sorlistview_search_bar_icon_normal=0x7f020005; 33 | public static final int sorlistview_show_head_toast_bg=0x7f020006; 34 | public static final int sortlistview_sidebar_background=0x7f020007; 35 | } 36 | public static final class id { 37 | public static final int action_settings=0x7f090006; 38 | public static final int catalog=0x7f090004; 39 | public static final int country_lvcountry=0x7f090001; 40 | public static final int dialog=0x7f090002; 41 | public static final int filter_edit=0x7f090000; 42 | public static final int sidrbar=0x7f090003; 43 | public static final int title=0x7f090005; 44 | } 45 | public static final class layout { 46 | public static final int activity_listview_sort_main=0x7f030000; 47 | public static final int item_sort_listview=0x7f030001; 48 | } 49 | public static final class menu { 50 | public static final int main=0x7f080000; 51 | } 52 | public static final class string { 53 | public static final int action_settings=0x7f060001; 54 | public static final int app_name=0x7f060000; 55 | public static final int hello_world=0x7f060002; 56 | } 57 | public static final class style { 58 | /** 59 | Base application theme, dependent on API level. This theme is replaced 60 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 61 | 62 | 63 | 64 | Theme customizations available in newer API levels can go in 65 | res/values-vXX/styles.xml, while customizations related to 66 | backward-compatibility can go here. 67 | 68 | 69 | 70 | Base application theme for API 11+. This theme completely replaces 71 | AppBaseTheme from res/values/styles.xml on API 11+ devices. 72 | 73 | API 11 theme customizations can go here. 74 | 75 | Base application theme for API 14+. This theme completely replaces 76 | AppBaseTheme from BOTH res/values/styles.xml and 77 | res/values-v11/styles.xml on API 14+ devices. 78 | 79 | API 14 theme customizations can go here. 80 | */ 81 | public static final int AppBaseTheme=0x7f070000; 82 | /** Application theme. 83 | */ 84 | public static final int AppTheme=0x7f070001; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/com/example/provinceselector/SideBar.java: -------------------------------------------------------------------------------- 1 | package com.example.provinceselector; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.Color; 6 | import android.graphics.Paint; 7 | import android.graphics.Typeface; 8 | import android.graphics.drawable.ColorDrawable; 9 | import android.util.AttributeSet; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.widget.TextView; 13 | 14 | public class SideBar extends View { 15 | // 触摸事件 16 | private OnTouchingLetterChangedListener onTouchingLetterChangedListener; 17 | // 26个字母 18 | public static String[] b = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "#" }; 19 | private int choose = -1;// 选中 20 | private Paint paint = new Paint(); 21 | 22 | private TextView mTextDialog; 23 | 24 | public void setTextView(TextView mTextDialog) { 25 | this.mTextDialog = mTextDialog; 26 | } 27 | 28 | public SideBar(Context context, AttributeSet attrs, int defStyle) { 29 | super(context, attrs, defStyle); 30 | } 31 | 32 | public SideBar(Context context, AttributeSet attrs) { 33 | super(context, attrs); 34 | } 35 | 36 | public SideBar(Context context) { 37 | super(context); 38 | } 39 | 40 | /** 41 | * 重写这个方法 42 | */ 43 | protected void onDraw(Canvas canvas) { 44 | super.onDraw(canvas); 45 | // 获取焦点改变背景颜色. 46 | int height = getHeight();// 获取对应高度 47 | int width = getWidth(); // 获取对应宽度 48 | int singleHeight = height / b.length;// 获取每一个字母的高度 49 | 50 | for (int i = 0; i < b.length; i++) { 51 | paint.setColor(Color.rgb(33, 65, 98)); 52 | // paint.setColor(Color.WHITE); 53 | paint.setTypeface(Typeface.DEFAULT_BOLD); 54 | paint.setAntiAlias(true); 55 | paint.setTextSize(20); 56 | // 选中的状态 57 | if (i == choose) { 58 | paint.setColor(Color.parseColor("#3399ff")); 59 | paint.setFakeBoldText(true); 60 | } 61 | // x坐标等于中间-字符串宽度的一半. 62 | float xPos = width / 2 - paint.measureText(b[i]) / 2; 63 | float yPos = singleHeight * i + singleHeight; 64 | canvas.drawText(b[i], xPos, yPos, paint); 65 | paint.reset();// 重置画笔 66 | } 67 | 68 | } 69 | 70 | @Override 71 | public boolean dispatchTouchEvent(MotionEvent event) { 72 | final int action = event.getAction(); 73 | final float y = event.getY();// 点击y坐标 74 | final int oldChoose = choose; 75 | final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener; 76 | final int c = (int) (y / getHeight() * b.length);// 点击y坐标所占总高度的比例*b数组的长度就等于点击b中的个数. 77 | 78 | switch (action) { 79 | case MotionEvent.ACTION_UP: 80 | setBackgroundDrawable(new ColorDrawable(0x00000000)); 81 | choose = -1;// 82 | invalidate(); 83 | if (mTextDialog != null) { 84 | mTextDialog.setVisibility(View.INVISIBLE); 85 | } 86 | break; 87 | 88 | default: 89 | // 设置右侧字母列表[A,B,C,D,E....]的背景颜色 90 | setBackgroundResource(R.drawable.sortlistview_sidebar_background); 91 | if (oldChoose != c) { 92 | if (c >= 0 && c < b.length) { 93 | if (listener != null) { 94 | listener.onTouchingLetterChanged(b[c]); 95 | } 96 | if (mTextDialog != null) { 97 | mTextDialog.setText(b[c]); 98 | mTextDialog.setVisibility(View.VISIBLE); 99 | } 100 | 101 | choose = c; 102 | invalidate(); 103 | } 104 | } 105 | 106 | break; 107 | } 108 | return true; 109 | } 110 | 111 | /** 112 | * 向外公开的方法 113 | * 114 | * @param onTouchingLetterChangedListener 115 | */ 116 | public void setOnTouchingLetterChangedListener(OnTouchingLetterChangedListener onTouchingLetterChangedListener) { 117 | this.onTouchingLetterChangedListener = onTouchingLetterChangedListener; 118 | } 119 | 120 | /** 121 | * 接口 122 | * 123 | * @author coder 124 | * 125 | */ 126 | public interface OnTouchingLetterChangedListener { 127 | public void onTouchingLetterChanged(String s); 128 | } 129 | 130 | } -------------------------------------------------------------------------------- /src/com/example/provinceselector/ClearEditText.java: -------------------------------------------------------------------------------- 1 | package com.example.provinceselector; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.text.Editable; 6 | import android.text.TextWatcher; 7 | import android.util.AttributeSet; 8 | import android.view.MotionEvent; 9 | import android.view.View; 10 | import android.view.View.OnFocusChangeListener; 11 | import android.view.animation.Animation; 12 | import android.view.animation.CycleInterpolator; 13 | import android.view.animation.TranslateAnimation; 14 | import android.widget.EditText; 15 | 16 | public class ClearEditText extends EditText implements OnFocusChangeListener, TextWatcher { 17 | /** 18 | * 删除按钮的引用 19 | */ 20 | private Drawable mClearDrawable; 21 | 22 | public ClearEditText(Context context) { 23 | this(context, null); 24 | } 25 | 26 | public ClearEditText(Context context, AttributeSet attrs) { 27 | // 这里构造方法也很重要,不加这个很多属性不能再XML里面定义 28 | this(context, attrs, android.R.attr.editTextStyle); 29 | } 30 | 31 | public ClearEditText(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | init(); 34 | } 35 | 36 | private void init() { 37 | // 获取EditText的DrawableRight,假如没有设置我们就使用默认的图片 38 | mClearDrawable = getCompoundDrawables()[2]; 39 | if (mClearDrawable == null) { 40 | mClearDrawable = getResources().getDrawable(R.drawable.sorlistview_emotionstore_progresscancelbtn); 41 | } 42 | mClearDrawable.setBounds(0, 0, mClearDrawable.getIntrinsicWidth(), mClearDrawable.getIntrinsicHeight()); 43 | setClearIconVisible(false); 44 | setOnFocusChangeListener(this); 45 | addTextChangedListener(this); 46 | } 47 | 48 | /** 49 | * 因为我们不能直接给EditText设置点击事件,所以我们用记住我们按下的位置来模拟点击事件 当我们按下的位置 在 EditText的宽度 - 50 | * 图标到控件右边的间距 - 图标的宽度 和 EditText的宽度 - 图标到控件右边的间距之间我们就算点击了图标,竖直方向没有考虑 51 | */ 52 | @Override 53 | public boolean onTouchEvent(MotionEvent event) { 54 | if (getCompoundDrawables()[2] != null) { 55 | if (event.getAction() == MotionEvent.ACTION_UP) { 56 | boolean touchable = event.getX() > (getWidth() - getPaddingRight() - mClearDrawable.getIntrinsicWidth()) && (event.getX() < ((getWidth() - getPaddingRight()))); 57 | if (touchable) { 58 | this.setText(""); 59 | } 60 | } 61 | } 62 | 63 | return super.onTouchEvent(event); 64 | } 65 | 66 | /** 67 | * 当ClearEditText焦点发生变化的时候,判断里面字符串长度设置清除图标的显示与隐藏 68 | */ 69 | @Override 70 | public void onFocusChange(View v, boolean hasFocus) { 71 | if (hasFocus) { 72 | setClearIconVisible(getText().length() > 0); 73 | } else { 74 | setClearIconVisible(false); 75 | } 76 | } 77 | 78 | /** 79 | * 设置清除图标的显示与隐藏,调用setCompoundDrawables为EditText绘制上去 80 | * 81 | * @param visible 82 | */ 83 | protected void setClearIconVisible(boolean visible) { 84 | Drawable right = visible ? mClearDrawable : null; 85 | setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1], right, getCompoundDrawables()[3]); 86 | } 87 | 88 | /** 89 | * 当输入框里面内容发生变化的时候回调的方法 90 | */ 91 | @Override 92 | public void onTextChanged(CharSequence s, int start, int count, int after) { 93 | setClearIconVisible(s.length() > 0); 94 | } 95 | 96 | @Override 97 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 98 | 99 | } 100 | 101 | @Override 102 | public void afterTextChanged(Editable s) { 103 | 104 | } 105 | 106 | /** 107 | * 设置晃动动画 108 | */ 109 | public void setShakeAnimation() { 110 | this.setAnimation(shakeAnimation(5)); 111 | } 112 | 113 | /** 114 | * 晃动动画 115 | * 116 | * @param counts 117 | * 1秒钟晃动多少下 118 | * @return 119 | */ 120 | public static Animation shakeAnimation(int counts) { 121 | Animation translateAnimation = new TranslateAnimation(0, 10, 0, 0); 122 | translateAnimation.setInterpolator(new CycleInterpolator(counts)); 123 | translateAnimation.setDuration(1000); 124 | return translateAnimation; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/com/example/provinceselector/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.provinceselector; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | import android.app.Activity; 8 | import android.os.Bundle; 9 | import android.text.Editable; 10 | import android.text.TextUtils; 11 | import android.text.TextWatcher; 12 | import android.view.View; 13 | import android.widget.AdapterView; 14 | import android.widget.AdapterView.OnItemClickListener; 15 | import android.widget.ListView; 16 | import android.widget.TextView; 17 | import android.widget.Toast; 18 | 19 | import com.example.provinceselector.SideBar.OnTouchingLetterChangedListener; 20 | 21 | public class MainActivity extends Activity { 22 | private ListView sortListView; 23 | private SideBar sideBar; 24 | private TextView dialog; 25 | private SortAdapter adapter; 26 | private ClearEditText mClearEditText; 27 | 28 | /** 29 | * 汉字转换成拼音的类 30 | */ 31 | private CharacterParser characterParser; 32 | private List SourceDateList; 33 | 34 | /** 35 | * 根据拼音来排列ListView里面的数据类 36 | */ 37 | private PinyinComparator pinyinComparator; 38 | 39 | @Override 40 | protected void onCreate(Bundle savedInstanceState) { 41 | super.onCreate(savedInstanceState); 42 | setContentView(R.layout.activity_listview_sort_main); 43 | initView(); 44 | } 45 | 46 | public void initView() { 47 | // 实例化汉字转拼音类 48 | characterParser = CharacterParser.getInstance(); 49 | 50 | pinyinComparator = new PinyinComparator(); 51 | 52 | sideBar = (SideBar) findViewById(R.id.sidrbar); 53 | dialog = (TextView) findViewById(R.id.dialog); 54 | sideBar.setTextView(dialog); 55 | 56 | // 设置右侧触摸监听 57 | sideBar.setOnTouchingLetterChangedListener(new OnTouchingLetterChangedListener() { 58 | 59 | @Override 60 | public void onTouchingLetterChanged(String s) { 61 | // 该字母首次出现的位置 62 | int position = adapter.getPositionForSection(s.charAt(0)); 63 | if (position != -1) { 64 | sortListView.setSelection(position); 65 | } 66 | 67 | } 68 | }); 69 | 70 | sortListView = (ListView) findViewById(R.id.country_lvcountry); 71 | sortListView.setOnItemClickListener(new OnItemClickListener() { 72 | 73 | @Override 74 | public void onItemClick(AdapterView parent, View view, int position, long id) { 75 | // 这里要利用adapter.getItem(position)来获取当前position所对应的对象 76 | Toast.makeText(getApplication(), ((SortModel) adapter.getItem(position)).getName(), Toast.LENGTH_SHORT).show(); 77 | } 78 | }); 79 | 80 | SourceDateList = filledData(getResources().getStringArray(R.array.date)); 81 | 82 | // 根据a-z进行排序源数据 83 | Collections.sort(SourceDateList, pinyinComparator); 84 | adapter = new SortAdapter(this, SourceDateList); 85 | sortListView.setAdapter(adapter); 86 | 87 | mClearEditText = (ClearEditText) findViewById(R.id.filter_edit); 88 | 89 | // 根据输入框输入值的改变来过滤搜索 90 | mClearEditText.addTextChangedListener(new TextWatcher() { 91 | 92 | @Override 93 | public void onTextChanged(CharSequence s, int start, int before, int count) { 94 | // 当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表 95 | filterData(s.toString()); 96 | } 97 | 98 | @Override 99 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 100 | 101 | } 102 | 103 | @Override 104 | public void afterTextChanged(Editable s) { 105 | } 106 | }); 107 | 108 | } 109 | 110 | /** 111 | * 为ListView填充数据 112 | * 113 | * @param date 114 | * @return 115 | */ 116 | private List filledData(String[] date) { 117 | List mSortList = new ArrayList(); 118 | 119 | for (int i = 0; i < date.length; i++) { 120 | SortModel sortModel = new SortModel(); 121 | sortModel.setName(date[i]); 122 | // 汉字转换成拼音 123 | String pinyin = characterParser.getSelling(date[i]); 124 | String sortString = pinyin.substring(0, 1).toUpperCase(); 125 | 126 | // 正则表达式,判断首字母是否是英文字母 127 | if (sortString.matches("[A-Z]")) { 128 | sortModel.setSortLetters(sortString.toUpperCase()); 129 | } else { 130 | sortModel.setSortLetters("#"); 131 | } 132 | 133 | mSortList.add(sortModel); 134 | } 135 | return mSortList; 136 | 137 | } 138 | 139 | /** 140 | * 根据输入框中的值来过滤数据并更新ListView 141 | * 142 | * @param filterStr 143 | */ 144 | private void filterData(String filterStr) { 145 | List filterDateList = new ArrayList(); 146 | 147 | if (TextUtils.isEmpty(filterStr)) { 148 | filterDateList = SourceDateList; 149 | } else { 150 | filterDateList.clear(); 151 | for (SortModel sortModel : SourceDateList) { 152 | String name = sortModel.getName(); 153 | if (name.indexOf(filterStr.toString()) != -1 || characterParser.getSelling(name).startsWith(filterStr.toString())) { 154 | filterDateList.add(sortModel); 155 | } 156 | } 157 | } 158 | 159 | // 根据a-z进行排序 160 | Collections.sort(filterDateList, pinyinComparator); 161 | adapter.updateListView(filterDateList); 162 | } 163 | 164 | } 165 | -------------------------------------------------------------------------------- /src/com/example/provinceselector/CharacterParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Filename CharacterParser.java 3 | * Company �Ϻ�����-�ֶ��ֹ�˾�� 4 | * @author LuRuihui 5 | * @version 0.1 6 | */ 7 | package com.example.provinceselector; 8 | 9 | /** 10 | * Java汉字转换为拼音 11 | * 12 | */ 13 | public class CharacterParser { 14 | private static int[] pyvalue = new int[] {-20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, -20230, -20051, -20036, -20032, 15 | -20026, -20002, -19990, -19986, -19982, -19976, -19805, -19784, -19775, -19774, -19763, -19756, -19751, -19746, -19741, -19739, -19728, 16 | -19725, -19715, -19540, -19531, -19525, -19515, -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, -19263, -19261, 17 | -19249, -19243, -19242, -19238, -19235, -19227, -19224, -19218, -19212, -19038, -19023, -19018, -19006, -19003, -18996, -18977, -18961, 18 | -18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, -18731, -18722, -18710, -18697, -18696, -18526, -18518, -18501, -18490, 19 | -18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220, -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988, 20 | -17970, -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, -17733, -17730, -17721, -17703, -17701, -17697, -17692, 21 | -17683, -17676, -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202, -17185, -16983, -16970, -16942, -16915, -16733, 22 | -16708, -16706, -16689, -16664, -16657, -16647, -16474, -16470, -16465, -16459, -16452, -16448, -16433, -16429, -16427, -16423, -16419, 23 | -16412, -16407, -16403, -16401, -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171, -16169, -16158, -16155, -15959, 24 | -15958, -15944, -15933, -15920, -15915, -15903, -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, -15652, -15640, -15631, 25 | -15625, -15454, -15448, -15436, -15435, -15419, -15416, -15408, -15394, -15385, -15377, -15375, -15369, -15363, -15362, -15183, -15180, 26 | -15165, -15158, -15153, -15150, -15149, -15144, -15143, -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, -14941, 27 | -14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921, -14914, -14908, -14902, -14894, -14889, -14882, -14873, -14871, -14857, 28 | -14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594, -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, 29 | -14345, -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, -14125, -14123, -14122, -14112, -14109, -14099, -14097, -14094, 30 | -14092, -14090, -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, -13894, -13878, -13870, -13859, -13847, -13831, 31 | -13658, -13611, -13601, -13406, -13404, -13400, -13398, -13395, -13391, -13387, -13383, -13367, -13359, -13356, -13343, -13340, -13329, 32 | -13326, -13318, -13147, -13138, -13120, -13107, -13096, -13095, -13091, -13076, -13068, -13063, -13060, -12888, -12875, -12871, -12860, 33 | -12858, -12852, -12849, -12838, -12831, -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359, -12346, -12320, -12300, 34 | -12120, -12099, -12089, -12074, -12067, -12058, -12039, -11867, -11861, -11847, -11831, -11798, -11781, -11604, -11589, -11536, -11358, 35 | -11340, -11339, -11324, -11303, -11097, -11077, -11067, -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, -11014, 36 | -10838, -10832, -10815, -10800, -10790, -10780, -10764, -10587, -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315, -10309, 37 | -10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254}; 38 | public static String[] pystr = new String[] {"a", "ai", "an", "ang", "ao", "ba", "bai", "ban", "bang", "bao", "bei", "ben", "beng", "bi", "bian", 39 | "biao", "bie", "bin", "bing", "bo", "bu", "ca", "cai", "can", "cang", "cao", "ce", "ceng", "cha", "chai", "chan", "chang", "chao", "che", 40 | "chen", "cheng", "chi", "chong", "chou", "chu", "chuai", "chuan", "chuang", "chui", "chun", "chuo", "ci", "cong", "cou", "cu", "cuan", 41 | "cui", "cun", "cuo", "da", "dai", "dan", "dang", "dao", "de", "deng", "di", "dian", "diao", "die", "ding", "diu", "dong", "dou", "du", 42 | "duan", "dui", "dun", "duo", "e", "en", "er", "fa", "fan", "fang", "fei", "fen", "feng", "fo", "fou", "fu", "ga", "gai", "gan", "gang", 43 | "gao", "ge", "gei", "gen", "geng", "gong", "gou", "gu", "gua", "guai", "guan", "guang", "gui", "gun", "guo", "ha", "hai", "han", "hang", 44 | "hao", "he", "hei", "hen", "heng", "hong", "hou", "hu", "hua", "huai", "huan", "huang", "hui", "hun", "huo", "ji", "jia", "jian", 45 | "jiang", "jiao", "jie", "jin", "jing", "jiong", "jiu", "ju", "juan", "jue", "jun", "ka", "kai", "kan", "kang", "kao", "ke", "ken", 46 | "keng", "kong", "kou", "ku", "kua", "kuai", "kuan", "kuang", "kui", "kun", "kuo", "la", "lai", "lan", "lang", "lao", "le", "lei", "leng", 47 | "li", "lia", "lian", "liang", "liao", "lie", "lin", "ling", "liu", "long", "lou", "lu", "lv", "luan", "lue", "lun", "luo", "ma", "mai", 48 | "man", "mang", "mao", "me", "mei", "men", "meng", "mi", "mian", "miao", "mie", "min", "ming", "miu", "mo", "mou", "mu", "na", "nai", 49 | "nan", "nang", "nao", "ne", "nei", "nen", "neng", "ni", "nian", "niang", "niao", "nie", "nin", "ning", "niu", "nong", "nu", "nv", "nuan", 50 | "nue", "nuo", "o", "ou", "pa", "pai", "pan", "pang", "pao", "pei", "pen", "peng", "pi", "pian", "piao", "pie", "pin", "ping", "po", "pu", 51 | "qi", "qia", "qian", "qiang", "qiao", "qie", "qin", "qing", "qiong", "qiu", "qu", "quan", "que", "qun", "ran", "rang", "rao", "re", 52 | "ren", "reng", "ri", "rong", "rou", "ru", "ruan", "rui", "run", "ruo", "sa", "sai", "san", "sang", "sao", "se", "sen", "seng", "sha", 53 | "shai", "shan", "shang", "shao", "she", "shen", "sheng", "shi", "shou", "shu", "shua", "shuai", "shuan", "shuang", "shui", "shun", 54 | "shuo", "si", "song", "sou", "su", "suan", "sui", "sun", "suo", "ta", "tai", "tan", "tang", "tao", "te", "teng", "ti", "tian", "tiao", 55 | "tie", "ting", "tong", "tou", "tu", "tuan", "tui", "tun", "tuo", "wa", "wai", "wan", "wang", "wei", "wen", "weng", "wo", "wu", "xi", 56 | "xia", "xian", "xiang", "xiao", "xie", "xin", "xing", "xiong", "xiu", "xu", "xuan", "xue", "xun", "ya", "yan", "yang", "yao", "ye", "yi", 57 | "yin", "ying", "yo", "yong", "you", "yu", "yuan", "yue", "yun", "za", "zai", "zan", "zang", "zao", "ze", "zei", "zen", "zeng", "zha", 58 | "zhai", "zhan", "zhang", "zhao", "zhe", "zhen", "zheng", "zhi", "zhong", "zhou", "zhu", "zhua", "zhuai", "zhuan", "zhuang", "zhui", 59 | "zhun", "zhuo", "zi", "zong", "zou", "zu", "zuan", "zui", "zun", "zuo"}; 60 | private StringBuilder buffer; 61 | private String resource; 62 | private static CharacterParser characterParser = new CharacterParser(); 63 | 64 | public static CharacterParser getInstance() { 65 | return characterParser; 66 | } 67 | 68 | public String getResource() { 69 | return resource; 70 | } 71 | 72 | public void setResource(String resource) { 73 | this.resource = resource; 74 | } 75 | 76 | /** * 汉字转成ASCII码 * * @param chs * @return */ 77 | private int getChsAscii(String chs) { 78 | int asc = 0; 79 | try { 80 | byte[] bytes = chs.getBytes("gb2312"); 81 | if (bytes == null || bytes.length > 2 || bytes.length <= 0) { 82 | throw new RuntimeException("illegal resource string"); 83 | } 84 | if (bytes.length == 1) { 85 | asc = bytes[0]; 86 | } 87 | if (bytes.length == 2) { 88 | int hightByte = 256 + bytes[0]; 89 | int lowByte = 256 + bytes[1]; 90 | asc = (256 * hightByte + lowByte) - 256 * 256; 91 | } 92 | } catch (Exception e) { 93 | System.out.println("ERROR:ChineseSpelling.class-getChsAscii(String chs)" + e); 94 | } 95 | return asc; 96 | } 97 | 98 | /** * 单字解析 * * @param str * @return */ 99 | public String convert(String str) { 100 | String result = null; 101 | int ascii = getChsAscii(str); 102 | if (ascii > 0 && ascii < 160) { 103 | result = String.valueOf((char) ascii); 104 | } else { 105 | for (int i = (pyvalue.length - 1); i >= 0; i--) { 106 | if (pyvalue[i] <= ascii) { 107 | result = pystr[i]; 108 | break; 109 | } 110 | } 111 | } 112 | return result; 113 | } 114 | 115 | /** * 词组解析 * * @param chs * @return */ 116 | public String getSelling(String chs) { 117 | String key, value; 118 | buffer = new StringBuilder(); 119 | for (int i = 0; i < chs.length(); i++) { 120 | key = chs.substring(i, i + 1); 121 | if (key.getBytes().length >= 2) { 122 | value = (String) convert(key); 123 | if (value == null) { 124 | value = "unknown"; 125 | } 126 | } else { 127 | value = key; 128 | } 129 | buffer.append(value); 130 | } 131 | return buffer.toString(); 132 | } 133 | 134 | public String getSpelling() { 135 | return this.getSelling(this.getResource()); 136 | } 137 | 138 | } 139 | --------------------------------------------------------------------------------