├── .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 |
28 |
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 |
16 |
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 |
7 |
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 |
47 |
49 |
53 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/res/layout/city_hot_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/layout/city_locate_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
8 |
11 |
14 |
17 |
21 |
22 |
24 |
26 |
27 |
29 |
31 |
34 |
35 |
--------------------------------------------------------------------------------
/res/layout/city_search_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
10 |
13 |
16 |
17 |
19 |
21 |
--------------------------------------------------------------------------------
/res/layout/empty_search_city_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
9 |
13 |
17 |
18 |
--------------------------------------------------------------------------------
/res/layout/overlay.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
--------------------------------------------------------------------------------
/res/layout/public_cityhot.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
9 |
10 |
15 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/res/layout/public_cityhot_allcity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
11 |
--------------------------------------------------------------------------------
/res/layout/public_cityhot_header_padding.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
--------------------------------------------------------------------------------
/res/layout/public_cityhot_header_padding_blank.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/res/layout/public_cityhot_header_searchview.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/res/layout/public_cityhot_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
14 |
18 |
20 |
21 |
--------------------------------------------------------------------------------
/res/layout/public_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
7 |
10 |
14 |
19 |
20 |
22 |
25 |
34 |
41 |
42 |
45 |
48 |
52 |
56 |
57 |
58 |
59 |
63 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/res/layout/searchlayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
20 |
24 |
28 |
41 |
47 |
48 |
49 |
50 |
53 |
--------------------------------------------------------------------------------
/res/raw/china_city_name:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/res/raw/china_city_name
--------------------------------------------------------------------------------
/res/values/color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #fff0efed
4 | #ff7e7e7e
5 | #fffdfdfd
6 | #ff171717
7 | #ffd7d7d7
8 | #ff333333
9 | #ffff8200
10 | #ff999999
11 | #ffffff
12 | #ffe1e1e1
13 | #ffd9d9d9
14 | #B2B8AD
15 | #ffeff0f2
16 | #ff585858
17 | #fffff4de
18 | #68BF36
19 | #00B2EE
20 | #77ff0000
21 | #F2B8CE
22 | #B3557A
23 | #0000
24 | #ff000000
25 | #34000000
26 | #ff0079ff
27 | #b0000000
28 | #60000000
29 | #c0ffff00
30 | #00FFFF
31 | #3ff70000
32 | #B551A5
33 | #299BE8
34 | #44DAFF
35 | #6CB5B5
36 | #ffecf0f1
37 | #ffffffff
38 | #fff1c40f
39 | #ff8c8c8c
40 | #ffdddddc
41 | #ff5c5c5c
42 | #ff161616
43 | #ff787878
44 | #fffefefe
45 | #ffefefef
46 | #c0000000
47 | #ff333333
48 | #ff495a6d
49 | #ffff6a22
50 | #ffff6a22
51 | #FF5000
52 |
53 | #FFFFFF
54 |
55 | #000000
56 |
57 | #CCCCCC
58 |
59 |
60 | #EEEEEE
61 |
62 |
63 | #FFFFFF
64 |
65 | #000000
66 |
67 | #CC0000
68 |
69 | #CCCCCC
70 | #00000000
71 | #fff2f2f2
72 |
73 | #FFFFF0
74 |
75 | #FFFFE0
76 |
77 | #FFFF00
78 |
79 | #FFFAFA
80 |
81 | #FFFAF0
82 |
83 | #FFFACD
84 |
85 | #FFF8DC
86 |
87 | #FFF5EE
88 |
89 | #FFF0F5
90 |
91 | #FFEFD5
92 |
93 | #FFEBCD
94 |
95 | #FFE4E1
96 |
97 | #FFE4C4
98 |
99 | #FFE4B5
100 |
101 | #FFDEAD
102 |
103 | #FFDAB9
104 |
105 | #FFD700
106 |
107 | #FFC0CB
108 |
109 | #FFB6C1
110 |
111 | #FFA07A
112 |
113 | #FF8C00
114 |
115 | #FF7F50
116 |
117 | #FF69B4
118 |
119 | #FF6347
120 |
121 | #FF4500
122 |
123 | #FF1493
124 |
125 | #FF00FF
126 |
127 | #FF00FF
128 |
129 | #FDF5E6
130 |
131 | #FAFAD2
132 |
133 | #FAF0E6
134 |
135 | #FAEBD7
136 |
137 | #FA8072
138 |
139 | #F8F8FF
140 |
141 | #F5FFFA
142 |
143 | #F5F5F5
144 |
145 | #F5F5DC
146 |
147 | #F5DEB3
148 |
149 | #F4A460
150 |
151 | #F0FFFF
152 |
153 | #F0FFF0
154 |
155 | #F0F8FF
156 |
157 | #F0E68C
158 |
159 | #F08080
160 |
161 | #EEE8AA
162 |
163 | #EE82EE
164 |
165 | #E9967A
166 |
167 | #E6E6FA
168 |
169 | #E0FFFF
170 |
171 | #DEB887
172 |
173 | #DDA0DD
174 |
175 | #DCDCDC
176 |
177 | #DC143C
178 |
179 | #DB7093
180 |
181 | #DAA520
182 |
183 | #DA70D6
184 |
185 | #D8BFD8
186 |
187 | #D3D3D3
188 |
189 | #D3D3D3
190 |
191 | #D2B48C
192 |
193 | #D2691E
194 |
195 | #CD853F
196 |
197 | #CD5C5C
198 |
199 | #C71585
200 |
201 | #C0C0C0
202 |
203 | #BDB76B
204 |
205 | #BC8F8F
206 |
207 | #BA55D3
208 |
209 | #B8860B
210 |
211 | #B22222
212 |
213 | #B0E0E6
214 |
215 | #B0C4DE
216 |
217 | #AFEEEE
218 |
219 | #ADFF2F
220 |
221 | #ADD8E6
222 |
223 | #A9A9A9
224 |
225 | #A9A9A9
226 |
227 | #A52A2A
228 |
229 | #A0522D
230 |
231 | #9932CC
232 |
233 | #98FB98
234 |
235 | #9400D3
236 |
237 | #9370DB
238 |
239 | #90EE90
240 |
241 | #8FBC8F
242 |
243 | #8B4513
244 |
245 | #8B008B
246 |
247 | #8B0000
248 |
249 | #8A2BE2
250 |
251 | #87CEFA
252 |
253 | #87CEEB
254 |
255 | #808080
256 |
257 | #808000
258 |
259 | #800000
260 |
261 | #7FFFD4
262 |
263 | #7FFF00
264 |
265 | #7CFC00
266 |
267 | #7B68EE
268 |
269 | #778899
270 |
271 | #778899
272 |
273 | #708090
274 |
275 | #708090
276 |
277 | #6B8E23
278 |
279 | #6A5ACD
280 |
281 | #696969
282 |
283 | #696969
284 |
285 | #66CDAA
286 |
287 | #6495ED
288 |
289 | #5F9EA0
290 |
291 | #556B2F
292 |
293 | #4B0082
294 |
295 | #48D1CC
296 |
297 | #483D8B
298 |
299 | #4682B4
300 |
301 | #4169E1
302 |
303 | #40E0D0
304 |
305 | #3CB371
306 |
307 | #32CD32
308 |
309 | #2F4F4F
310 |
311 | #2F4F4F
312 |
313 | #2E8B57
314 |
315 | #228B22
316 |
317 | #20B2AA
318 |
319 | #1E90FF
320 |
321 | #191970
322 |
323 | #00FFFF
324 |
325 | #00FFFF
326 |
327 | #00FF7F
328 |
329 | #00FF00
330 |
331 | #00FA9A
332 |
333 | #00CED1
334 |
335 | #00BFFF
336 |
337 | #008B8B
338 |
339 | #008080
340 |
341 | #008000
342 |
343 | #006400
344 |
345 | #0000CD
346 |
347 | #00008B
348 |
349 | #000080
350 |
351 | #EDEDED
352 | #ff000000
353 | #ffffffff
354 | #ffcccccc
355 | #ff404040
356 | #ffffffff
357 | #ffc0c0c0
358 | #c000ff00
359 | #ffffffff
360 | #ff808080
361 | #ffffffff
362 | #fffff0e0
363 | #ffffffff
364 | #ff000000
365 | #ff4b4b4b
366 | #ff000000
367 | #ffffffff
368 | #50000000
369 | #ffffffff
370 | #ff000000
371 | #ffff0000
372 | #58567D
373 | #686868
374 |
375 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 6.669983dip
3 | 14.669983sp
4 | 20.0dip
5 | 5.0dip
6 | 45.0dip
7 | 44.0dip
8 | 68.69998dip
9 | 14.0sp
10 | 17.299988sp
11 | 48.0dip
12 | 20.0dip
13 | 55.0dip
14 | 44.0dip
15 | 20.0dip
16 | 40.0dip
17 | 36.0dip
18 | 14.0sp
19 | 16.0dip
20 | 12.0dip
21 | 30.599976dip
22 | 18.0sp
23 | 16.0sp
24 | 10.0dip
25 | 20.0dip
26 |
27 |
28 | 16dp
29 | 16dp
30 | 50dp
31 | 16sp
32 |
33 | 10dp
34 | 28dp
35 | 28dp
36 |
37 | 10dp
38 | 28dp
39 | 28dp
40 |
41 | 68dp
42 | 68dp
43 |
44 | 8dp
45 | 8dp
46 | 16dp
47 |
48 | 74px
49 | 40px
50 | 58px
51 | 53px
52 | 92px
53 | 39px
54 | 26px
55 |
56 |
57 | 12sp
58 | 13sp
59 | 14sp
60 | 15sp
61 | 16sp
62 | 17sp
63 | 18sp
64 | 19sp
65 | 20sp
66 | 21sp
67 | 22sp
68 | 0dp
69 | 0.5dp
70 | 1dp
71 | 2dp
72 | 3dp
73 | 4dp
74 | 5dp
75 | 6dp
76 | 7dp
77 | 8dp
78 | 9dp
79 | 10dp
80 | 11dp
81 | 12dp
82 | 13dp
83 | 14dp
84 | 15dp
85 | 16dp
86 | 17dp
87 | 18dp
88 | 19dp
89 | 20dp
90 | 21dp
91 | 22dp
92 | 23dp
93 | 24dp
94 | 25dp
95 | 26dp
96 | 27dp
97 | 28dp
98 | 29dp
99 | 30dp
100 | 31dp
101 | 32dp
102 | 33dp
103 | 34dp
104 | 35dp
105 | 36dp
106 | 37dp
107 | 38dp
108 | 39dp
109 | 40dp
110 | 41dp
111 | 42dp
112 | 43dp
113 | 44dp
114 | 45dp
115 | 46dp
116 | 47dp
117 | 48dp
118 | 49dp
119 | 50dp
120 | 51dp
121 | 52dp
122 | 53dp
123 | 54dp
124 | 55dp
125 | 56dp
126 | 57dp
127 | 58dp
128 | 59dp
129 | 60dp
130 | 61dp
131 | 62dp
132 | 63dp
133 | 64dp
134 | 65dp
135 | 66dp
136 | 67dp
137 | 68dp
138 | 69dp
139 | 70dp
140 | 71dp
141 | 72dp
142 | 73dp
143 | 74dp
144 | 75dp
145 | 13.0sp
146 | 12.0sp
147 | 16.0sp
148 | 18.0sp
149 | 14.0sp
150 |
151 | 40.0dip
152 |
--------------------------------------------------------------------------------
/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - #00000000
4 | - #ffdddddd
5 | - #ffffffff
6 | - #fffcb8a6
7 | - #ffff6622
8 | - #ffcc5223
9 |
10 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 定位中
3 | 搜索
4 | 抱歉,未找到!
5 | 请输入关键字
6 | 定位为
7 | ,是否切换?
8 | 热门城市
9 | 定位城市
10 | 关闭
11 | 请输入城市名,首字母或拼音
12 | 加载中
13 |
14 | 取消
15 | 城市列表
16 | 取 消
17 | 提示
18 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
21 |
28 |
29 |
35 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiuSecret/citylist/f33fedb796e5c753b9919574016bff0e035e7a4f/screenshot.png
--------------------------------------------------------------------------------
/src/com/gugalor/adapter/HotCityGridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 | import com.gugalor.citylist.R;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by Administrator on 2015/6/29.
16 | */
17 |
18 | public final class HotCityGridAdapter extends BaseAdapter
19 | {
20 | private List list = new ArrayList();
21 | private Context context;
22 |
23 | public HotCityGridAdapter(Context paramContext, List paramList)
24 | {
25 | this.list = paramList;
26 | this.context = paramContext;
27 | }
28 |
29 | public final int getCount()
30 | {
31 | return this.list.size();
32 | }
33 |
34 | public final Object getItem(int paramInt)
35 | {
36 | return this.list.get(paramInt);
37 | }
38 |
39 | public final long getItemId(int paramInt)
40 | {
41 | return paramInt;
42 | }
43 |
44 | public final View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
45 | {
46 | MyHolder myHolder = null;
47 | if (paramView == null) {
48 | myHolder = new MyHolder();
49 | paramView = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.city_hot_item_layout, null);
50 | paramView.setTag(myHolder);
51 | myHolder.textView = (TextView) paramView.findViewById(R.id.city_hot_text);
52 | } else {
53 | myHolder = (MyHolder) paramView.getTag();
54 | }
55 | myHolder.textView.setText(list.get(paramInt));
56 | return paramView;
57 | }
58 |
59 | private final class MyHolder {
60 | TextView textView;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/com/gugalor/adapter/MyGridView.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.adapter;
2 |
3 | /**
4 | * Created by Administrator on 2015/6/29.
5 | */
6 | import android.content.Context;
7 | import android.util.AttributeSet;
8 | import android.view.View;
9 | import android.widget.GridView;
10 |
11 | public class MyGridView extends GridView
12 | {
13 | public MyGridView(Context paramContext)
14 | {
15 | super(paramContext);
16 | }
17 |
18 | public MyGridView(Context paramContext, AttributeSet paramAttributeSet)
19 | {
20 | super(paramContext, paramAttributeSet);
21 | }
22 |
23 | public MyGridView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
24 | {
25 | super(paramContext, paramAttributeSet, paramInt);
26 | }
27 |
28 | public void onMeasure(int paramInt1, int paramInt2)
29 | {
30 | super.onMeasure(paramInt1, View.MeasureSpec.makeMeasureSpec(536870911, MeasureSpec.AT_MOST));
31 |
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/gugalor/adapter/TitleButton.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.adapter;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.Button;
6 | import android.widget.TextView;
7 |
8 | public class TitleButton extends Button
9 | {
10 | private boolean a = false;
11 |
12 | public TitleButton(Context paramContext)
13 | {
14 | super(paramContext);
15 | }
16 |
17 | public TitleButton(Context paramContext, AttributeSet paramAttributeSet)
18 | {
19 | super(paramContext, paramAttributeSet);
20 | }
21 |
22 | public TitleButton(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
23 | {
24 | super(paramContext, paramAttributeSet, paramInt);
25 | }
26 |
27 | public void setText(CharSequence paramCharSequence, TextView.BufferType paramBufferType)
28 | {
29 | if ((paramCharSequence != null) && (!"".equals(paramCharSequence)))
30 | {
31 | int i = 3;
32 | if (this.a)
33 | i = 2;
34 | if (paramCharSequence.length() > i + 1)
35 | paramCharSequence = paramCharSequence.subSequence(0, i) + "...";
36 | }
37 | super.setText(paramCharSequence, paramBufferType);
38 | }
39 | }
--------------------------------------------------------------------------------
/src/com/gugalor/application/PinyinSearchApplication.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.application;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | public class PinyinSearchApplication extends Application {
7 | private static Context mContext;
8 |
9 | @Override
10 | public void onCreate() {
11 | super.onCreate();
12 | mContext=getApplicationContext();
13 | }
14 |
15 | public static Context getContextObject(){
16 | return mContext;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/CityList.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.database.Cursor;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.graphics.PixelFormat;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.view.*;
12 | import android.view.ViewGroup.LayoutParams;
13 | import android.widget.*;
14 | import android.widget.AdapterView.OnItemClickListener;
15 | import com.baidu.location.BDLocation;
16 | import com.baidu.location.BDLocationListener;
17 | import com.baidu.location.LocationClient;
18 | import com.baidu.location.LocationClientOption;
19 | import com.gugalor.adapter.HotCityGridAdapter;
20 | import com.gugalor.helper.ContactsHelper;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Arrays;
24 | import java.util.HashMap;
25 | import java.util.List;
26 | /**
27 | * 城市选择
28 | *
29 | * @author gugalor
30 | */
31 | public class CityList extends Activity {
32 | private BaseAdapter adapter;
33 | private ListView mCityLit;
34 | private TextView overlay, citysearch;
35 | private Button backbutton;
36 | private MyLetterListView letterListView;
37 | private HashMap alphaIndexer;
38 | private String[] sections;
39 | private Handler handler;
40 | private OverlayThread overlayThread;
41 | private SQLiteDatabase database;
42 | private ArrayList mCityNames;
43 | private View city_locating_state;
44 | private View city_locate_failed;
45 | private TextView city_locate_state;
46 | private ProgressBar city_locating_progress;
47 | private ImageView city_locate_success_img;
48 | private LocationClient locationClient = null;
49 |
50 | View hotcityall;
51 |
52 | String[] hotcity = new String[]{"北京", "上海", "广州", "深圳", "杭州", "南京", "天津", "武汉", "重庆"};
53 | WindowManager windowManager;
54 | @Override
55 | public void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | LayoutInflater localLayoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
58 | View city_layout = localLayoutInflater.inflate(R.layout.public_cityhot, null);
59 | setContentView(city_layout);
60 |
61 | citysearch = (TextView) city_layout.findViewById(R.id.city_search_edittext);
62 | backbutton = (Button) city_layout.findViewById(R.id.title_left_txt_btn);
63 | mCityLit = (ListView) city_layout.findViewById(R.id.public_allcity_list);
64 | letterListView = (MyLetterListView) city_layout.findViewById(R.id.cityLetterListView);
65 |
66 | View cityhot_header_blank = localLayoutInflater.inflate(R.layout.public_cityhot_header_padding_blank, mCityLit, false);
67 | mCityLit.addHeaderView(cityhot_header_blank, null, false);
68 | cityhot_header_blank = localLayoutInflater.inflate(R.layout.city_locate_layout, mCityLit, false);
69 | city_locating_state = cityhot_header_blank.findViewById(R.id.city_locating_state);
70 | city_locate_state = ((TextView) cityhot_header_blank.findViewById(R.id.city_locate_state));
71 | city_locating_progress = ((ProgressBar) cityhot_header_blank.findViewById(R.id.city_locating_progress));
72 | city_locate_success_img = ((ImageView) cityhot_header_blank.findViewById(R.id.city_locate_success_img));
73 | city_locate_failed = cityhot_header_blank.findViewById(R.id.city_locate_failed);
74 | mCityLit.addHeaderView(cityhot_header_blank);
75 |
76 | View hotheadview = localLayoutInflater.inflate(R.layout.public_cityhot_header_padding, mCityLit, false);
77 | mCityLit.addHeaderView(hotheadview, null, false);
78 | hotcityall = localLayoutInflater.inflate(R.layout.public_cityhot_allcity, mCityLit, false);
79 | final GridView localGridView = (GridView) hotcityall.findViewById(R.id.public_hotcity_list);
80 |
81 | mCityLit.addHeaderView(hotcityall);
82 | HotCityGridAdapter adapter = new HotCityGridAdapter(this, Arrays.asList(hotcity));
83 | localGridView.setAdapter(adapter);
84 | localGridView.setOnItemClickListener(new OnItemClickListener() {
85 | @Override
86 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
87 | String cityModel = parent.getAdapter()
88 | .getItem(position).toString();
89 | Setting.Save2SharedPreferences(CityList.this, "city",
90 | cityModel);
91 | Intent intent =new Intent();
92 | intent.putExtra("city",cityModel);
93 | setResult(2,intent);
94 | finish();
95 | }
96 | });
97 |
98 | city_locating_state.setOnClickListener(new View.OnClickListener() {
99 | @Override
100 | public void onClick(View v) {
101 | String cityModel=city_locate_state.getText().toString();
102 | Setting.Save2SharedPreferences(CityList.this, "city",
103 | cityModel);
104 | Intent intent =new Intent();
105 | intent.putExtra("city",cityModel);
106 | setResult(2,intent);
107 | finish();
108 | }
109 | });
110 | loadLocation();
111 |
112 |
113 | DBManager dbManager = new DBManager(this);
114 | dbManager.openDateBase();
115 | dbManager.closeDatabase();
116 | database = SQLiteDatabase.openOrCreateDatabase(DBManager.DB_PATH + "/"
117 | + DBManager.DB_NAME, null);
118 | mCityNames = getCityNames();
119 | database.close();
120 | letterListView
121 | .setOnTouchingLetterChangedListener(new LetterListViewListener());
122 | alphaIndexer = new HashMap();
123 | handler = new Handler();
124 | overlayThread = new OverlayThread();
125 | initOverlay();
126 | setAdapter(mCityNames);
127 | mCityLit.setOnItemClickListener(new CityListOnItemClick());
128 | backbutton.setOnClickListener(new View.OnClickListener() {
129 | @Override
130 | public void onClick(View v) {
131 | finish();
132 | }
133 | });
134 | citysearch.setOnTouchListener(new View.OnTouchListener() {
135 | @Override
136 | public boolean onTouch(View v, MotionEvent event) {
137 | boolean startLoad = ContactsHelper.getInstance().startLoadContacts();
138 |
139 | Intent intent = new Intent(CityList.this, searchactivity.class);
140 | startActivityForResult(intent, 2);
141 | return false;
142 | }
143 | });
144 |
145 |
146 | }
147 |
148 | @Override
149 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
150 | switch (resultCode) {
151 | case RESULT_OK:
152 | String city=data.getStringExtra("city");
153 | Intent intent =new Intent();
154 | intent.putExtra("city",city);
155 | setResult(2,intent);
156 | finish();
157 | break;
158 |
159 | default:
160 | break;
161 | }
162 | }
163 |
164 | /**
165 | * 获取位置
166 | */
167 | public void loadLocation() {
168 |
169 | city_locate_failed.setVisibility(View.GONE);
170 | city_locate_state.setVisibility(View.VISIBLE);
171 | city_locating_progress.setVisibility(View.VISIBLE);
172 | city_locate_success_img.setVisibility(View.GONE);
173 | city_locate_state.setText(getString(R.string.locating));
174 | if (locationClient == null) {
175 | locationClient = new LocationClient(CityList.this);
176 | locationClient.registerLocationListener(new LocationListenner());
177 | LocationClientOption option = new LocationClientOption();
178 | option.setAddrType("all");
179 | option.setOpenGps(true);
180 | option.setCoorType("bd09ll");
181 | option.setScanSpan(2000);
182 | locationClient.setLocOption(option);
183 | }
184 |
185 | locationClient.start();
186 | locationClient.requestLocation();
187 | }
188 |
189 | /**
190 | * 监听函数,又新位置的时候,格式化成字符串,输出到屏幕中
191 | */
192 | private class LocationListenner implements BDLocationListener {
193 | public void onReceiveLocation(BDLocation location) {
194 | city_locating_progress.setVisibility(View.GONE);
195 |
196 | if (location != null) {
197 |
198 | if (location.getCity() != null
199 | && !location.getCity().equals("")) {
200 | locationClient.stop();
201 | city_locate_failed.setVisibility(View.GONE);
202 | city_locate_state.setVisibility(View.VISIBLE);
203 | city_locating_progress.setVisibility(View.GONE);
204 | city_locate_success_img.setVisibility(View.VISIBLE);
205 | city_locate_state.setText(location.getCity());
206 |
207 | } else {
208 | city_locating_state.setVisibility(View.GONE);
209 | city_locate_failed.setVisibility(View.VISIBLE);
210 | }
211 | } else {
212 | // 定位失败
213 | city_locating_state.setVisibility(View.GONE);
214 | city_locate_failed.setVisibility(View.VISIBLE);
215 | }
216 |
217 | }
218 | }
219 |
220 | /**
221 | * @return
222 | */
223 | private ArrayList getCityNames() {
224 | ArrayList names = new ArrayList();
225 | Cursor cursor = database.rawQuery(
226 | "SELECT * FROM T_City ORDER BY NameSort", null);
227 | for (int i = 0; i < cursor.getCount(); i++) {
228 | cursor.moveToPosition(i);
229 | CityModel cityModel = new CityModel();
230 | cityModel.setCityName(cursor.getString(cursor
231 | .getColumnIndex("CityName")));
232 | cityModel.setNameSort(cursor.getString(cursor
233 | .getColumnIndex("NameSort")));
234 | names.add(cityModel);
235 | }
236 | cursor.close();
237 | return names;
238 | }
239 |
240 | /**
241 | * б 1/4
242 | *
243 | * @author
244 | */
245 | class CityListOnItemClick implements OnItemClickListener {
246 |
247 | @Override
248 | public void onItemClick(AdapterView> arg0, View arg1, int pos,
249 | long arg3) {
250 | CityModel cityModel = (CityModel) mCityLit.getAdapter()
251 | .getItem(pos);
252 | if(cityModel!=null) {
253 | Setting.Save2SharedPreferences(CityList.this, "city",
254 | cityModel.getCityName());
255 | Intent intent =new Intent();
256 | intent.putExtra("city",cityModel.getCityName());
257 | setResult(2,intent);
258 | finish();
259 | }
260 | }
261 |
262 | }
263 |
264 | /**
265 | * ListView
266 | *
267 | * @param list
268 | */
269 | private void setAdapter(List list) {
270 | if (list != null) {
271 | adapter = new ListAdapter(this, list);
272 | mCityLit.setAdapter(adapter);
273 | }
274 |
275 | }
276 |
277 | /**
278 | * ListViewAdapter
279 | *
280 | * @author gugalor
281 | */
282 | private class ListAdapter extends BaseAdapter {
283 | private LayoutInflater inflater;
284 | private List list;
285 |
286 | public ListAdapter(Context context, List list) {
287 |
288 | this.inflater = LayoutInflater.from(context);
289 | this.list = list;
290 | alphaIndexer = new HashMap();
291 | sections = new String[list.size()];
292 |
293 | for (int i = 0; i < list.size(); i++) {
294 | //
295 | // getAlpha(list.get(i));
296 | String currentStr = list.get(i).getNameSort();
297 | //
298 | String previewStr = (i - 1) >= 0 ? list.get(i - 1)
299 | .getNameSort() : " ";
300 | if (!previewStr.equals(currentStr)) {
301 | String name = list.get(i).getNameSort();
302 | alphaIndexer.put(name, i);
303 | sections[i] = name;
304 | }
305 | }
306 |
307 | }
308 |
309 | @Override
310 | public int getCount() {
311 | return list.size();
312 | }
313 |
314 | @Override
315 | public Object getItem(int position) {
316 | return list.get(position);
317 | }
318 |
319 | @Override
320 | public long getItemId(int position) {
321 | return position;
322 | }
323 |
324 | @Override
325 | public View getView(int position, View convertView, ViewGroup parent) {
326 | ViewHolder holder;
327 | if (convertView == null) {
328 | convertView = inflater.inflate(R.layout.public_cityhot_item,
329 | null);
330 | holder = new ViewHolder();
331 | holder.alpha = (TextView) convertView.findViewById(R.id.alpha);
332 | holder.name = (TextView) convertView
333 | .findViewById(R.id.public_cityhot_item_textview);
334 | convertView.setTag(holder);
335 | } else {
336 | holder = (ViewHolder) convertView.getTag();
337 | }
338 |
339 | holder.name.setText(list.get(position).getCityName());
340 | String currentStr = list.get(position).getNameSort();
341 | String previewStr = (position - 1) >= 0 ? list.get(position - 1)
342 | .getNameSort() : " ";
343 | if (!previewStr.equals(currentStr)) {
344 | holder.alpha.setVisibility(View.VISIBLE);
345 | holder.alpha.setText(currentStr);
346 | } else {
347 | holder.alpha.setVisibility(View.GONE);
348 | }
349 | return convertView;
350 | }
351 |
352 | private class ViewHolder {
353 | TextView alpha;
354 | TextView name;
355 | }
356 |
357 | }
358 |
359 | // ’
360 | private void initOverlay() {
361 | LayoutInflater inflater = LayoutInflater.from(this);
362 | overlay = (TextView) inflater.inflate(R.layout.overlay, null);
363 | overlay.setVisibility(View.INVISIBLE);
364 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
365 | LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
366 | WindowManager.LayoutParams.TYPE_APPLICATION,
367 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
368 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
369 | PixelFormat.TRANSLUCENT);
370 | windowManager = (WindowManager) this
371 | .getSystemService(Context.WINDOW_SERVICE);
372 | windowManager.addView(overlay, lp);
373 | }
374 | @Override
375 | protected void onDestroy() {
376 | windowManager.removeView(overlay);
377 | super.onDestroy();
378 | }
379 | private class LetterListViewListener implements
380 | MyLetterListView.OnTouchingLetterChangedListener {
381 |
382 | @Override
383 | public void onTouchingLetterChanged(final String s) {
384 | if (alphaIndexer.get(s) != null) {
385 | int position = alphaIndexer.get(s);
386 | mCityLit.setSelection(position);
387 | overlay.setText(sections[position]);
388 | overlay.setVisibility(View.VISIBLE);
389 | handler.removeCallbacks(overlayThread);
390 | // Уoverlay
391 | handler.postDelayed(overlayThread, 1500);
392 | }
393 | }
394 |
395 | }
396 |
397 | // overlay
398 | private class OverlayThread implements Runnable {
399 |
400 | @Override
401 | public void run() {
402 | overlay.setVisibility(View.GONE);
403 | }
404 |
405 | }
406 |
407 | }
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/CityModel.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | /**
4 | * 城市属性实体类
5 | * @author gugalor
6 | *
7 | */
8 | public class CityModel
9 | {
10 | private String CityName; //城市名字
11 | private String NameSort; //城市首字母
12 |
13 | public String getCityName()
14 | {
15 | return CityName;
16 | }
17 |
18 | public void setCityName(String cityName)
19 | {
20 | CityName = cityName;
21 | }
22 |
23 | public String getNameSort()
24 | {
25 | return NameSort;
26 | }
27 |
28 | public void setNameSort(String nameSort)
29 | {
30 | NameSort = nameSort;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/CitysearchAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 | import com.gugalor.model.Contacts;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by gugalor on 14-5-31.
15 | */
16 | public class CitysearchAdapter extends BaseAdapter {
17 | private List mList;
18 | private Context mContext;
19 |
20 | public CitysearchAdapter(List list, Context context) {
21 | mList = list;
22 | mContext = context;
23 | }
24 |
25 | public void refresh(List list) {
26 | mList = list;
27 | notifyDataSetChanged();
28 | }
29 |
30 |
31 | @Override
32 | public int getCount() {
33 | return mList.size();
34 | }
35 |
36 | @Override
37 | public Object getItem(int position) {
38 | return mList.get(position);
39 | }
40 |
41 | @Override
42 | public long getItemId(int position) {
43 | return position;
44 | }
45 |
46 | @Override
47 | public View getView(int position, View convertView, ViewGroup parent) {
48 | Holder holder = null;
49 | if (convertView == null) {
50 | LayoutInflater inflater = LayoutInflater.from(mContext);
51 | convertView = inflater.inflate(R.layout.city_search_list_item, null);
52 | holder = new Holder();
53 | holder.mNameText = (TextView) convertView.findViewById(R.id.area);
54 | convertView.setTag(holder);
55 | } else {
56 | holder = (Holder) convertView.getTag();
57 | }
58 | final Contacts cityModel = (Contacts) mList.get(position);
59 | holder.mNameText.setText(cityModel.getName());
60 | return convertView;
61 | }
62 |
63 | class Holder {
64 | private TextView mNameText, mIDText;
65 | }
66 | }
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/CitysearchNonAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.TextView;
9 | import com.gugalor.model.Contacts;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Created by gugalor on 14-5-31.
15 | */
16 | public class CitysearchNonAdapter extends BaseAdapter {
17 | private Context mContext;
18 |
19 | public CitysearchNonAdapter(Context context) {
20 | mContext = context;
21 | }
22 |
23 | public void refresh(List list) {
24 | notifyDataSetChanged();
25 | }
26 |
27 | @Override
28 | public int getCount() {
29 | return 1;
30 | }
31 |
32 | @Override
33 | public Object getItem(int i) {
34 | return null;
35 | }
36 |
37 | @Override
38 | public long getItemId(int position) {
39 | return position;
40 | }
41 |
42 | @Override
43 | public View getView(int position, View convertView, ViewGroup parent) {
44 | LayoutInflater inflater = LayoutInflater.from(mContext);
45 | convertView = inflater.inflate(R.layout.empty_search_city_item, null);
46 |
47 | return convertView;
48 | }
49 |
50 | class Holder {
51 | private TextView mNameText, mIDText;
52 | }
53 | }
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/DBManager.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.os.Environment;
6 |
7 | import java.io.*;
8 |
9 | /**
10 | * rawеlдdata
11 | * @author gugalor
12 | *
13 | */
14 | public class DBManager
15 | {
16 | private final int BUFFER_SIZE = 400000;
17 | private static final String PACKAGE_NAME = "com.gugalor.citylist";
18 | public static final String DB_NAME = "china_city_name.db";
19 | public static final String DB_PATH = "/data" + Environment.getDataDirectory().getAbsolutePath() + "/" + PACKAGE_NAME ; // ·
20 | private Context mContext;
21 | private SQLiteDatabase database;
22 |
23 | public DBManager(Context context)
24 | {
25 | this.mContext = context;
26 | }
27 |
28 | /**
29 | * ÷
30 | */
31 | public void openDateBase()
32 | {
33 | this.database = this.openDateBase(DB_PATH + "/" + DB_NAME);
34 |
35 | }
36 |
37 | /**
38 | *
39 | *
40 | * @param dbFile
41 | * @return SQLiteDatabase
42 | * @author gugalor
43 | */
44 | private SQLiteDatabase openDateBase(String dbFile)
45 | {
46 | File file = new File(dbFile);
47 | if (!file.exists())
48 | {
49 | // // rawеlstream
50 | InputStream stream = this.mContext.getResources().openRawResource(R.raw.china_city_name);
51 | try
52 | {
53 |
54 | // stream дdata
55 | FileOutputStream outputStream = new FileOutputStream(dbFile);
56 | byte[] buffer = new byte[BUFFER_SIZE];
57 | int count = 0;
58 | while ((count = stream.read(buffer)) > 0)
59 | {
60 | outputStream.write(buffer, 0, count);
61 | }
62 | outputStream.close();
63 | stream.close();
64 | SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbFile, null);
65 | return db;
66 | } catch (FileNotFoundException e)
67 | {
68 | // TODO Auto-generated catch block
69 | e.printStackTrace();
70 | } catch (IOException e)
71 | {
72 | // TODO Auto-generated catch block
73 | e.printStackTrace();
74 | }
75 | }
76 | return database;
77 | }
78 |
79 | public void closeDatabase()
80 | {
81 | if (database != null && database.isOpen())
82 | {
83 | this.database.close();
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/MyLetterListView.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.util.AttributeSet;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 |
11 | public class MyLetterListView extends View
12 | {
13 |
14 | OnTouchingLetterChangedListener onTouchingLetterChangedListener;
15 | 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" };
16 | int choose = -1;
17 | Paint paint = new Paint();
18 | boolean showBkg = false;
19 |
20 | public MyLetterListView(Context context, AttributeSet attrs, int defStyle)
21 | {
22 | super(context, attrs, defStyle);
23 | }
24 |
25 | public MyLetterListView(Context context, AttributeSet attrs)
26 | {
27 | super(context, attrs);
28 | }
29 |
30 | public MyLetterListView(Context context)
31 | {
32 | super(context);
33 | }
34 |
35 | @Override
36 | protected void onDraw(Canvas canvas)
37 | {
38 | super.onDraw(canvas);
39 | if (showBkg)
40 | {
41 | canvas.drawColor(Color.parseColor("#00000000"));
42 | }
43 |
44 | int height = getHeight();
45 | int width = getWidth();
46 | int singleHeight = height / b.length;
47 | for (int i = 0; i < b.length; i++)
48 | {
49 | paint.setTextSize(getResources().getDimension(R.dimen.city_letter_size));
50 | paint.setColor(Color.parseColor("#77736B"));
51 | paint.setAntiAlias(true);
52 | if (i == choose)
53 | {
54 | paint.setColor(Color.parseColor("#ff7800"));
55 | }
56 | float xPos = width / 2 - paint.measureText(b[i]) / 2;
57 | float yPos = singleHeight * i + singleHeight;
58 | canvas.drawText(b[i], xPos, yPos, paint);
59 | paint.reset();
60 | }
61 |
62 | }
63 |
64 | @Override
65 | public boolean dispatchTouchEvent(MotionEvent event)
66 | {
67 | final int action = event.getAction();
68 | final float y = event.getY();
69 | final int oldChoose = choose;
70 | final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener;
71 | final int c = (int) (y / getHeight() * b.length);
72 |
73 | switch (action) {
74 | case MotionEvent.ACTION_DOWN:
75 | showBkg = true;
76 | if (oldChoose != c && listener != null)
77 | {
78 | if (c > 0 && c < b.length)
79 | {
80 | listener.onTouchingLetterChanged(b[c]);
81 | choose = c;
82 | invalidate();
83 | }
84 | }
85 |
86 | break;
87 | case MotionEvent.ACTION_MOVE:
88 | if (oldChoose != c && listener != null)
89 | {
90 | if (c > 0 && c < b.length)
91 | {
92 | listener.onTouchingLetterChanged(b[c]);
93 | choose = c;
94 | invalidate();
95 | }
96 | }
97 | break;
98 | case MotionEvent.ACTION_UP:
99 | showBkg = false;
100 | choose = -1;
101 | invalidate();
102 | break;
103 | }
104 | return true;
105 | }
106 |
107 | @Override
108 | public boolean onTouchEvent(MotionEvent event)
109 | {
110 | return super.onTouchEvent(event);
111 | }
112 |
113 | public void setOnTouchingLetterChangedListener(OnTouchingLetterChangedListener onTouchingLetterChangedListener)
114 | {
115 | this.onTouchingLetterChangedListener = onTouchingLetterChangedListener;
116 | }
117 |
118 | public interface OnTouchingLetterChangedListener
119 | {
120 | public void onTouchingLetterChanged(String s);
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/Setting.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.content.SharedPreferences.Editor;
7 | import android.preference.PreferenceManager;
8 |
9 | /**
10 | * 公共参数配置类
11 | *
12 | * @author gugalor
13 | *
14 | */
15 | public class Setting {
16 |
17 |
18 | public static String LoadFromSharedPreferences(Context context, String key) {
19 | SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
20 | return mPrefs.getString(key, "");
21 | }
22 |
23 | public static void Save2SharedPreferences(Context context, String key, String value) {
24 | SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
25 | SharedPreferences.Editor ed = mPrefs.edit();
26 | ed.putString(key, value);
27 | ed.commit();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/citychangdialog.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.app.Dialog;
4 | import android.content.Context;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 |
11 | /**
12 | * Created by gugalor on 2015/6/12.
13 | */
14 | public class citychangdialog extends Dialog {
15 | private Button city_change_again, city_change_cancel;
16 | private TextView changmsg;
17 | private Context context;
18 | private String cityName;
19 | private ClickListenerInterface clickListenerInterface;
20 |
21 | public citychangdialog(Context context, String string) {
22 | super(context, R.style.MyDialog);
23 | this.context = context;
24 | this.cityName=string;
25 | }
26 |
27 | @Override
28 | public void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | View view = LayoutInflater.from(context).inflate(R.layout.city_change_dailog, null);
31 | setContentView(view);
32 | city_change_again = (Button) view.findViewById(R.id.city_change_again);
33 | city_change_cancel = (Button) view.findViewById(R.id.city_change_cancel);
34 | changmsg = (TextView) view.findViewById(R.id.city_change_msg);
35 | changmsg.setText(context.getString(R.string.locatez_as)+cityName+context.getString(R.string.switch_ornot));
36 | city_change_again.setOnClickListener(new clickListener());
37 | city_change_cancel.setOnClickListener(new clickListener());
38 | }
39 |
40 | public interface ClickListenerInterface {
41 |
42 | public void doConfirm();
43 |
44 | public void doCancel();
45 | }
46 |
47 | public void setClicklistener(ClickListenerInterface clickListenerInterface) {
48 | this.clickListenerInterface = clickListenerInterface;
49 | }
50 |
51 | private class clickListener implements View.OnClickListener {
52 | @Override
53 | public void onClick(View v) {
54 | int id = v.getId();
55 | switch (id) {
56 | case R.id.city_change_again:
57 | clickListenerInterface.doConfirm();
58 | break;
59 | case R.id.city_change_cancel:
60 | clickListenerInterface.doCancel();
61 | break;
62 | }
63 | }
64 | }
65 | }
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/home.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | /**
10 | * Created by Administrator on 2015/7/3.
11 | */
12 | public class home extends Activity{
13 | TextView location_text;
14 |
15 | @Override
16 | public void onCreate(final Bundle savedInstanceState){
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_home);
19 |
20 | location_text=(TextView)findViewById(R.id.home_location_text);
21 | location_text.setOnClickListener(new View.OnClickListener() {
22 | @Override
23 | public void onClick(View view) {
24 | Intent intent = new Intent(home.this, CityList.class);
25 | startActivityForResult(intent, 1);
26 | }
27 | });
28 |
29 | }
30 |
31 | @Override
32 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
33 | if (data != null)
34 | switch (resultCode) {
35 | case 2:
36 | location_text.setText(data.getStringExtra("city"));
37 | break;
38 |
39 | default:
40 | break;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/com/gugalor/citylist/searchactivity.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.citylist;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.os.Bundle;
8 | import android.text.Editable;
9 | import android.text.TextUtils;
10 | import android.text.TextWatcher;
11 | import android.view.View;
12 | import android.widget.*;
13 | import com.gugalor.helper.ContactsHelper;
14 | import com.gugalor.model.Contacts;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by gugalor
20 | */
21 | public class searchactivity extends Activity {
22 | ListView searchresult;
23 | private EditText input;
24 | private ImageButton clear,left;
25 | private SQLiteDatabase database;
26 |
27 | @Override
28 | protected void onCreate(Bundle savedInstanceState) {
29 | super.onCreate(savedInstanceState);
30 | setContentView(R.layout.searchlayout);
31 | searchresult = (ListView) findViewById(R.id.searchresult);
32 | input = (EditText) findViewById(R.id.input);
33 | clear = (ImageButton) findViewById(R.id.clear);
34 | left=(ImageButton)findViewById(R.id.left_title_button);
35 | database = SQLiteDatabase.openOrCreateDatabase(DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
36 | clear.setOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View view) {
39 | input.setText("");
40 | }
41 | });
42 | final CitysearchAdapter adapter = new CitysearchAdapter(ContactsHelper.mSearchContacts, this);
43 | left.setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View view) {
46 | finish();
47 | }
48 | });
49 |
50 | searchresult.setAdapter(adapter);
51 | searchresult.setOnItemClickListener(new AdapterView.OnItemClickListener() {
52 | @Override
53 | public void onItemClick(AdapterView> adapterView, View view, int position, long l) {
54 | final Contacts cityModel = (Contacts)ContactsHelper.mSearchContacts.get(position);
55 | Setting.Save2SharedPreferences(searchactivity.this, "city",
56 | cityModel.getName());
57 | Intent intent =new Intent();
58 | intent.putExtra("city",cityModel.getName());
59 | setResult(RESULT_OK,intent);
60 | finish();
61 |
62 | }
63 | });
64 |
65 | input.addTextChangedListener(new TextWatcher() {
66 |
67 | @Override
68 | public void afterTextChanged(Editable s) {
69 | String curCharacter=s.toString().trim();
70 |
71 | if(TextUtils.isEmpty(curCharacter)){
72 | clear.setVisibility(View.INVISIBLE);
73 | ContactsHelper.getInstance().parseQwertyInputSearchContacts(null);
74 | }else{
75 | clear.setVisibility(View.VISIBLE);
76 | ContactsHelper.getInstance().parseQwertyInputSearchContacts(curCharacter);
77 | }
78 | if(ContactsHelper.mSearchContacts.size()==0){
79 | searchresult.setAdapter(new CitysearchNonAdapter(searchactivity.this));
80 | }else {
81 | searchresult.setAdapter(adapter);
82 | adapter.refresh(ContactsHelper.mSearchContacts);
83 | }
84 | }
85 |
86 | @Override
87 | public void beforeTextChanged(CharSequence s, int start, int count,
88 | int after) {
89 |
90 | }
91 |
92 | @Override
93 | public void onTextChanged(CharSequence s, int start, int before,
94 | int count) {
95 | }
96 |
97 | });
98 |
99 |
100 | }
101 | /**
102 | * 从数据库获取城市数据
103 | *
104 | * @return
105 | */
106 | private ArrayList getCityNames(String string)
107 | {
108 | ArrayList names = new ArrayList();
109 | Cursor cursor = database.rawQuery("SELECT CityName FROM T_City where CityName like '%"+string+"%' ORDER BY NameSort", null);
110 | for (int i = 0; i < cursor.getCount(); i++)
111 | {
112 | cursor.moveToPosition(i);
113 | CityModel cityModel = new CityModel();
114 | cityModel.setCityName(cursor.getString(cursor.getColumnIndex("CityName")));
115 | names.add(cityModel);
116 | }
117 | return names;
118 | }
119 |
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/com/gugalor/helper/ContactsHelper.java:
--------------------------------------------------------------------------------
1 | package com.gugalor.helper;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.os.AsyncTask;
8 | import android.os.AsyncTask.Status;
9 | import android.provider.ContactsContract;
10 | import android.util.Log;
11 | import com.gugalor.application.PinyinSearchApplication;
12 | import com.gugalor.citylist.DBManager;
13 | import com.gugalor.model.Contacts;
14 | import com.pinyinsearch.model.PinyinBaseUnit;
15 | import com.pinyinsearch.model.PinyinUnit;
16 | import com.pinyinsearch.util.PinyinUtil;
17 | import com.pinyinsearch.util.QwertyMatchPinyinUnits;
18 | import com.pinyinsearch.util.T9MatchPinyinUnits;
19 |
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.HashMap;
23 | import java.util.List;
24 |
25 | public class ContactsHelper {
26 | private static final String TAG = "ContactsHelper";
27 | private Context mContext;
28 | private static ContactsHelper mInstance = null;
29 | private List mBaseContacts = null; // The basic data used for the search
30 | public static List mSearchContacts = null; // The search results from the basic data
31 | /*
32 | * save the first input string which search no result.
33 | * mFirstNoSearchResultInput.size<=0, means that the first input string
34 | * which search no result not appear. mFirstNoSearchResultInput.size>0,
35 | * means that the first input string which search no result has appeared,
36 | * it's mFirstNoSearchResultInput.toString(). We can reduce the number of
37 | * search basic data by the first input string which search no result.
38 | */
39 | private StringBuffer mFirstNoSearchResultInput = null;
40 | private AsyncTask