Repository: Bigkoo/EasySideBar
Branch: master
Commit: afe9c698aef2
Files: 59
Total size: 83.2 KB
Directory structure:
gitextract_f_jovrni/
├── .gitignore
├── .idea/
│ ├── compiler.xml
│ ├── copyright/
│ │ └── profiles_settings.xml
│ ├── encodings.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── modules.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── README.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── demo/
│ │ └── ExampleInstrumentedTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── demo/
│ │ │ └── MainActivity.java
│ │ └── res/
│ │ ├── layout/
│ │ │ └── activity_main.xml
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── values-w820dp/
│ │ └── dimens.xml
│ └── test/
│ └── java/
│ └── com/
│ └── demo/
│ └── ExampleUnitTest.java
├── build.gradle
├── easysidebar/
│ ├── .gitignore
│ ├── build.gradle
│ ├── libs/
│ │ └── pinyin4j-2.5.0.jar
│ ├── proguard-rules.pro
│ └── src/
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── esaysidebar/
│ │ │ ├── EasySideBarBuilder.java
│ │ │ ├── activity/
│ │ │ │ ├── GridCityAdapter.java
│ │ │ │ ├── MyGridView.java
│ │ │ │ ├── SortAdapter.java
│ │ │ │ └── SortCityActivity.java
│ │ │ ├── bean/
│ │ │ │ └── CitySortModel.java
│ │ │ ├── lib/
│ │ │ │ ├── EasySideBar.java
│ │ │ │ └── EditTextWithDel.java
│ │ │ └── utils/
│ │ │ ├── PinyinComparator.java
│ │ │ └── PinyinUtils.java
│ │ └── res/
│ │ ├── drawable/
│ │ │ ├── edit_background.xml
│ │ │ ├── select_btn_white_gray.xml
│ │ │ └── selector_btn_press.xml
│ │ ├── layout/
│ │ │ ├── activity_sort_city.xml
│ │ │ ├── gridview_item.xml
│ │ │ ├── headview_hotcity.xml
│ │ │ ├── headview_loaction.xml
│ │ │ └── item_select_city.xml
│ │ ├── values/
│ │ │ ├── arrays.xml
│ │ │ ├── color.xml
│ │ │ ├── drawables.xml
│ │ │ └── strings.xml
│ │ └── values-w820dp/
│ │ └── dimens.xml
│ └── test/
│ └── java/
│ └── com/
│ └── demo/
│ └── ExampleUnitTest.java
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
================================================
FILE: .idea/compiler.xml
================================================
================================================
FILE: .idea/copyright/profiles_settings.xml
================================================
================================================
FILE: .idea/encodings.xml
================================================
================================================
FILE: .idea/gradle.xml
================================================
================================================
FILE: .idea/misc.xml
================================================
1.8
================================================
FILE: .idea/modules.xml
================================================
================================================
FILE: .idea/runConfigurations.xml
================================================
================================================
FILE: .idea/vcs.xml
================================================
================================================
FILE: README.md
================================================
# EasySideBar
一款按字母排序的库,已封装好城市数据,可定制化强,也可以下载源代码用Module的形式引入自己改一改来使用,也可稍做改造定制成通讯录。欢迎Star、提建议、提Issue。

## **使用步骤:**
### 1.添加Jcenter仓库 Gradle依赖:
```java
compile 'com.contrarywind:EasySideBar:1.1.0'
```
## 2.在Activity中添加如下代码:
```java
//热门城市数据 ,不添加数据的时候会隐藏该布局
ArrayList hotCityList = new ArrayList<>();
hotCityList.add("北京");
hotCityList.add("上海");
hotCityList.add("广州");
hotCityList.add("深圳");
hotCityList.add("杭州");
hotCityList.add("成都");
hotCityList.add("厦门");
hotCityList.add("天津");
hotCityList.add("武汉");
hotCityList.add("长沙");
//初始化以及配置
new EasySideBarBuilder(MainActivity.this)
.setTitle("城市选择")
/*.setIndexColor(Color.BLUE)*/
.setIndexColor(0xFF0095EE)
/*.isLazyRespond(true) //懒加载模式*/
.setHotCityList(hotCityList)//热门城市列表
.setIndexItems(mIndexItems)//索引字母
.setLocationCity("广州")//定位城市
.setMaxOffset(60)//索引的最大偏移量
.start();
```
## 3.在Activity中重写onActivityResult方法,接收回调数据:
```java
//resultCode 是使用封装好的EasySideBarBuilder.CODE_SIDEREQUEST
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case EasySideBarBuilder.CODE_SIDEREQUEST:
if (data!=null){
String city = data.getStringExtra("selected");
Toast.makeText(this,"选择的城市:"+city,Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
```
## Thanks
- [WaveSideBar](https://github.com/gjiazhe/WaveSideBar)
# License
```
Copyright 2014 Bigkoo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.easysidebar"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
compile project(path: ':easysidebar')
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in F:\Android-studio\SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: app/src/androidTest/java/com/demo/ExampleInstrumentedTest.java
================================================
package com.demo;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see Testing documentation
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.easysidebar", appContext.getPackageName());
}
}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
================================================
FILE: app/src/main/java/com/demo/MainActivity.java
================================================
package com.demo;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.esaysidebar.EasySideBarBuilder;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private final String[] mIndexItems = {"定位","热门"};//头部额外的索引
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
Button btn_sure = (Button)findViewById(R.id.btn_sure);
btn_sure.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList hotCityList = new ArrayList<>();
hotCityList.add("北京");
hotCityList.add("上海");
hotCityList.add("广州");
hotCityList.add("深圳");
hotCityList.add("杭州");
hotCityList.add("成都");
hotCityList.add("厦门");
hotCityList.add("天津");
hotCityList.add("武汉");
hotCityList.add("长沙");
new EasySideBarBuilder(MainActivity.this)
.setTitle("城市选择")
/*.setIndexColor(Color.BLUE)*/
.setIndexColor(0xFF0095EE)
/* .isLazyRespond(true) //懒加载模式*/
.setHotCityList(hotCityList)//热门城市列表
.setIndexItems(mIndexItems)//索引字母
.setLocationCity("广州")//定位城市
.setMaxOffset(60)//索引的最大偏移量
.start();
}
});
}
//数据回调
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case EasySideBarBuilder.CODE_SIDEREQUEST:
if (data!=null){
String city = data.getStringExtra("selected");
Toast.makeText(this,"选择的城市:"+city,Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
}
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: app/src/main/res/values/colors.xml
================================================
#3F51B5
#303F9F
#FF4081
================================================
FILE: app/src/main/res/values/dimens.xml
================================================
16dp
16dp
================================================
FILE: app/src/main/res/values/strings.xml
================================================
EasySideBar
================================================
FILE: app/src/main/res/values/styles.xml
================================================
================================================
FILE: app/src/main/res/values-w820dp/dimens.xml
================================================
64dp
================================================
FILE: app/src/test/java/com/demo/ExampleUnitTest.java
================================================
package com.demo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see Testing documentation
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.novoda:bintray-release:0.4.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: easysidebar/.gitignore
================================================
/build
================================================
FILE: easysidebar/build.gradle
================================================
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.novoda.bintray-release'//添加插件
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 1
versionName "1.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
allprojects {
tasks.withType(Javadoc) {//兼容中文字符
options{
encoding "UTF-8"
charSet 'UTF-8'
links "http://docs.oracle.com/javase/7/docs/api"
}
}
}
publish {
userOrg = 'contrarywind'//bintray.com 用户名/组织名 user/org name
groupId = 'com.contrarywind'//JCenter上显示的路径 path
artifactId = 'EasySideBar'//项目名称 project name
publishVersion = '1.0.1'//版本号 version code
desc = 'this is a sidebar for android'//项目描述 description
website = 'https://github.com/Bigkoo/EasySideBar' //项目网址链接 link
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
}
================================================
FILE: easysidebar/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in F:\Android-studio\SDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
================================================
FILE: easysidebar/src/main/AndroidManifest.xml
================================================
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/EasySideBarBuilder.java
================================================
package com.esaysidebar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.esaysidebar.activity.SortCityActivity;
import java.util.ArrayList;
/**
* TODO<建造器>
*
* @author: 小嵩
* @date: 2017/3/9 12:24
*/
public class EasySideBarBuilder {
private Context mContext;
public static final int CODE_SIDEREQUEST = 0x00000011; // ActivityForResult回调值
private String mtitleText;
private boolean isLazyRespond;
private String[] indexItems;
private String LocationCity;
private int indexColor= 0xFF666666;//默认索引文字颜色
private int maxOffset = 80;
private ArrayList HotCityList;//热门城市列表
public EasySideBarBuilder(Context context) {
this.mContext = context;
}
public EasySideBarBuilder setTitle(String titleText){
this.mtitleText = titleText;
return this;
}
public EasySideBarBuilder isLazyRespond(boolean isLazyRespond){
this.isLazyRespond = isLazyRespond;
return this;
}
public EasySideBarBuilder setIndexItems(String[] indexItems){
this.indexItems = indexItems;
return this;
}
public EasySideBarBuilder setLocationCity(String LocationCity){
this.LocationCity = LocationCity;
return this;
}
public EasySideBarBuilder setIndexColor(int indexColor){
this.indexColor = indexColor;
return this;
}
public EasySideBarBuilder setMaxOffset(int maxOffset){
this.maxOffset = maxOffset;
return this;
}
public EasySideBarBuilder setHotCityList(ArrayList HotCityList){
this.HotCityList = HotCityList;
return this;
}
public void start(){
Activity activity = (Activity) mContext;
Intent intent = new Intent(mContext, SortCityActivity.class);
intent.putExtra("titleText",mtitleText);
intent.putExtra("isLazyRespond",isLazyRespond);
intent.putExtra("indexItems",indexItems);
intent.putExtra("LocationCity",LocationCity);
intent.putExtra("indexColor",indexColor);
intent.putExtra("maxOffset",maxOffset);
intent.putStringArrayListExtra("HotCityList",HotCityList);
activity.startActivityForResult(intent,CODE_SIDEREQUEST);
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/activity/GridCityAdapter.java
================================================
package com.esaysidebar.activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.esaysidebar.R;
import java.util.List;
/**
* @TODO<按字母排序的选择页面- 热门城市列表适配器>
* @author 小嵩
* @date 2016-8-12 11:24:12
*/
public class GridCityAdapter extends ArrayAdapter {
/**
* 需要渲染的item布局文件
*/
private int resource;
public GridCityAdapter(Context context, int textViewResourceId, List objects) {
super(context, textViewResourceId, objects);
resource = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LinearLayout layout = null;
if (convertView == null) {
layout = (LinearLayout) LayoutInflater.from(getContext()).inflate(resource, null);
} else {
layout = (LinearLayout) convertView;
}
TextView name = (TextView) layout.findViewById(R.id.tv_city);
name.setText(getItem(position));
return layout;
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/activity/MyGridView.java
================================================
package com.esaysidebar.activity;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;
/**
* 自定义GridView,解决ScrollView嵌套Grideview只显示一行半
*/
public class MyGridView extends GridView {
public MyGridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyGridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyGridView(Context context) {
super(context);
}
/**
* 其中onMeasure函数决定了组件显示的高度与宽度;
* makeMeasureSpec函数中第一个函数决定布局空间的大小,第二个参数是布局模式
* MeasureSpec.AT_MOST的意思就是子控件需要多大的控件就扩展到多大的空间
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/activity/SortAdapter.java
================================================
package com.esaysidebar.activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.esaysidebar.R;
import com.esaysidebar.bean.CitySortModel;
import java.util.List;
public class SortAdapter extends BaseAdapter {
private List list = null;
private Context mContext;
public SortAdapter(Context mContext, List list) {
this.mContext = mContext;
this.list = list;
}
/**
* 当ListView数据发生变化时,调用此方法来更新ListView
*
* @param list
*/
public void updateListView(List list) {
this.list = list;
notifyDataSetChanged();
}
public int getCount() {
return this.list.size();
}
public Object getItem(int position) {
return list.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup arg2) {
ViewHolder viewHolder = null;
final CitySortModel mContent = list.get(position);
if (view == null) {
viewHolder = new ViewHolder();
view = LayoutInflater.from(mContext).inflate(R.layout.item_select_city, null);
viewHolder.tvTitle = (TextView) view.findViewById(R.id.tv_city_name);
view.setTag(viewHolder);
viewHolder.tvLetter = (TextView) view.findViewById(R.id.tv_catagory);
} else {
viewHolder = (ViewHolder) view.getTag();
}
int section = getSectionForPosition(position);
if (position == getPositionForSection(section)) {
viewHolder.tvLetter.setVisibility(View.VISIBLE);
viewHolder.tvLetter.setText(mContent.getSortLetters());
} else {
viewHolder.tvLetter.setVisibility(View.GONE);
}
viewHolder.tvTitle.setText(this.list.get(position).getName());
return view;
}
final static class ViewHolder {
TextView tvLetter;
TextView tvTitle;
}
public int getSectionForPosition(int position) {
return list.get(position).getSortLetters().charAt(0);
}
public int getPositionForSection(int section) {
for (int i = 0; i < getCount(); i++) {
String sortStr = list.get(i).getSortLetters();
char firstChar = sortStr.toUpperCase().charAt(0);
if (firstChar == section) {
return i;
}
}
return -1;
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/activity/SortCityActivity.java
================================================
package com.esaysidebar.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.esaysidebar.EasySideBarBuilder;
import com.esaysidebar.R;
import com.esaysidebar.bean.CitySortModel;
import com.esaysidebar.lib.EasySideBar;
import com.esaysidebar.utils.PinyinComparator;
import com.esaysidebar.utils.PinyinUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class SortCityActivity extends Activity {
private ListView sortListView;
private EasySideBar sideBar;
private TextView mTvTitle;
private TextView mTvLoaction,tv_label_location,tv_label_hot;
private ImageView iv_back;
private SortAdapter adapter;
private GridCityAdapter cityAdapter;//热门城市的适配器
private EditText mEtCityName;
private List SourceDateList;//内容数据源
private List HotCityList;//热门城市列表
private String titleText;//标题
private boolean isLazyRespond;//是否为懒加载
private String[] indexItems;//头部的索引值
private String LocationCity;//定位城市
private int indexColor;//索引文字颜色
private int maxOffset;//滑动特效 最大偏移量
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sort_city);
titleText = getIntent().getExtras().getString("titleText");
isLazyRespond = getIntent().getExtras().getBoolean("isLazyRespond");
indexItems = getIntent().getExtras().getStringArray("indexItems");
LocationCity = getIntent().getExtras().getString("LocationCity");
HotCityList = getIntent().getStringArrayListExtra("HotCityList");
if (HotCityList==null){
HotCityList = new ArrayList<>();
}
indexColor = getIntent().getIntExtra("indexColor",0xFF666666);//索引颜色
maxOffset = getIntent().getIntExtra("maxOffset",80);
initViews();
}
private void initViews() {
mEtCityName = (EditText) findViewById(R.id.et_search);
sideBar = (EasySideBar) findViewById(R.id.sidebar);
mTvTitle = (TextView) findViewById(R.id.tv_title);
sortListView = (ListView) findViewById(R.id.country_lvcountry);
iv_back = (ImageView) findViewById(R.id.iv_back);
sortListView.addHeaderView(initLocationHeadView());
sortListView.addHeaderView(initHotHeadView());
initSideBar();
initEvents();
setAdapter();
}
private void setAdapter() {
SourceDateList = filledData(getResources().getStringArray(R.array.provinces));
Collections.sort(SourceDateList, new PinyinComparator());
adapter = new SortAdapter(this, SourceDateList);
sortListView.setAdapter(adapter);
}
private void initEvents() {
//设置右侧触摸监听, (此处还需要优化)
sideBar.setOnSelectIndexItemListener(new EasySideBar.OnSelectIndexItemListener() {
@Override
public void onSelectIndexItem(int index, String value) {
//该字母首次出现的位置
int position = adapter.getPositionForSection(value.charAt(0));
if (position != -1) {
sortListView.setSelection(position + sortListView.getHeaderViewsCount());
}else {//未匹配到索引内容
for (int i= 0; i parent, View view, int position, long id) {
String city = ((CitySortModel) adapter.getItem(position - 1)).getName();
SentDataForResult(city);
}
});
//根据输入框输入值的改变来过滤搜索
mEtCityName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//当输入框里面的值为空,更新为原来的列表,否则为过滤数据列表
filterData(s.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
iv_back.setOnClickListener(new View.OnClickListener() {//点击 finish 掉页面
@Override
public void onClick(View v) {
SortCityActivity.this.finish();
}
});
}
private void initSideBar() {//初始化sidebar
//标题栏初始化
if (!TextUtils.isEmpty(titleText)){
mTvTitle.setVisibility(View.VISIBLE);
mTvTitle.setText(titleText);
}else {
mTvTitle.setVisibility(View.GONE);
}
sideBar.setLazyRespond(isLazyRespond);
sideBar.setTextColor(indexColor);
sideBar.setMaxOffset(maxOffset);
}
private View initHotHeadView() {
View headView = getLayoutInflater().inflate(R.layout.headview_hotcity, null);
GridView mGvCity = (GridView) headView.findViewById(R.id.gv_hot_city);
/* mTvLoaction =(TextView) headView.findViewById(R.id.tv_location_city);
tv_label_location =(TextView) headView.findViewById(R.id.tv_label_location);*/
tv_label_hot =(TextView) headView.findViewById(R.id.tv_label_hot);
if (HotCityList.size()<=0){//热门城市
tv_label_hot.setVisibility(View.GONE);
}else {
tv_label_hot.setVisibility(View.VISIBLE);
}
/* if (TextUtils.isEmpty(LocationCity)){//定位城市
mTvLoaction.setVisibility(View.GONE);
tv_label_location.setVisibility(View.GONE);
} else {
tv_label_location.setVisibility(View.VISIBLE);
mTvLoaction.setVisibility(View.VISIBLE);
mTvLoaction.setText(LocationCity);//设置定位城市
mTvLoaction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SentDataForResult(LocationCity);
}
});
}*/
cityAdapter = new GridCityAdapter(this, R.layout.gridview_item, HotCityList);
mGvCity.setAdapter(cityAdapter);
mGvCity.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
//选中的 Gird city
SentDataForResult(HotCityList.get(i));
}
});
return headView;
}
private View initLocationHeadView() {
View headView = getLayoutInflater().inflate(R.layout.headview_loaction, null);
mTvLoaction =(TextView) headView.findViewById(R.id.tv_location_city);
tv_label_location =(TextView) headView.findViewById(R.id.tv_label_location);
if (TextUtils.isEmpty(LocationCity)){//定位城市
mTvLoaction.setVisibility(View.GONE);
tv_label_location.setVisibility(View.GONE);
} else {
tv_label_location.setVisibility(View.VISIBLE);
mTvLoaction.setVisibility(View.VISIBLE);
mTvLoaction.setText(LocationCity);//设置定位城市
mTvLoaction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SentDataForResult(LocationCity);
}
});
}
return headView;
}
private void SentDataForResult(String city) {
Intent mIntent = new Intent();
mIntent.putExtra("selected", city);
SortCityActivity.this.setResult(EasySideBarBuilder.CODE_SIDEREQUEST, mIntent);
SortCityActivity.this.finish();
}
/**
* 根据输入框中的值来过滤数据并更新ListView
*
* @param filterStr
*/
private void filterData(String filterStr) {
List mSortList = new ArrayList<>();
if (TextUtils.isEmpty(filterStr)) {
mSortList = SourceDateList;
} else {
mSortList.clear();
for (CitySortModel sortModel : SourceDateList) {
String name = sortModel.getName();
/* name.toUpperCase().indexOf(filterStr.toString().toUpperCase()) != -1*/
if (name.toUpperCase().contains(filterStr.toString().toUpperCase()) || PinyinUtils.getPingYin(name).toUpperCase().startsWith(filterStr.toString().toUpperCase())) {
mSortList.add(sortModel);
}
}
}
// 根据a-z进行排序
Collections.sort(mSortList, new PinyinComparator());
adapter.updateListView(mSortList);
}
private List filledData(String[] date) {//获取数据,并根据拼音分类,添加index
List mSortList = new ArrayList<>();
ArrayList indexString = new ArrayList<>();//索引字母数组
boolean isGarbled = false;
for (int i = 0; i < date.length; i++) {
CitySortModel sortModel = new CitySortModel();
sortModel.setName(date[i]);
String pinyin = PinyinUtils.getPingYin(date[i]);
String sortString = pinyin.substring(0, 1).toUpperCase();
if (sortString.matches("[A-Z]")) {
sortModel.setSortLetters(sortString.toUpperCase());
if (!indexString.contains(sortString)) {
indexString.add(sortString);
}
}else{
sortModel.setSortLetters("#");
isGarbled = true;
}
mSortList.add(sortModel);
}
Collections.sort(indexString);
if (isGarbled){//出现乱码,将其添加到索引
indexString.add("#");
}
String[] IndexList = Concat(indexItems,indexString.toArray(new String[indexString.size()]));
sideBar.setIndexItems(IndexList); //只显示有内容部分的字母index
return mSortList;
}
private String[] Concat(String[] a,String[] b) {//合并两个数组
String[] mIndexItems = new String[a.length + b.length];
System.arraycopy(a, 0, mIndexItems, 0, a.length);
System.arraycopy(b, 0, mIndexItems, a.length, b.length);
return mIndexItems;
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/bean/CitySortModel.java
================================================
package com.esaysidebar.bean;
public class CitySortModel {
private String name;//显示的数据
private String sortLetters;//显示数据拼音的首字母
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSortLetters() {
return sortLetters;
}
public void setSortLetters(String sortLetters) {
this.sortLetters = sortLetters;
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/lib/EasySideBar.java
================================================
package com.esaysidebar.lib;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
import static android.R.attr.width;
/**
* @TODO
* @author 小嵩
* @date 2017-3-9 10:37:24
*/
public class EasySideBar extends View {
private final static int DEFAULT_TEXT_SIZE = 14; // sp
private final static int DEFAULT_MAX_OFFSET = 80; //dp
private final static String[] DEFAULT_INDEX_ITEMS = {"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", "#"};
private String[] mIndexItems;
/**
* the index in {@link #mIndexItems} of the current selected index item,
* it's reset to -1 when the finger up
*/
private int mCurrentIndex = -1;
/**
* Y coordinate of the point where finger is touching,
* the baseline is top of {@link #mStartTouchingArea}
* it's reset to -1 when the finger up
*/
private float mCurrentY = -1;
private Paint mPaint;
private int mTextColor;
private float mTextSize;
private int MaxHeight;
private int MaxWidth;
/**
* the Height of each index item
*/
private float mIndexItemHeight;
/**
* offset of the current selected index item
*/
private float mMaxOffset;
/**
* {@link #mStartTouching} will be set to true when {@link MotionEvent#ACTION_DOWN}
* happens in this area, and the side bar should start working.
*/
private RectF mStartTouchingArea = new RectF();
/**
* Height and width of {@link #mStartTouchingArea}
*/
private float mBarHeight;
private float mBarWidth;
/**
* Flag that the finger is starting touching.
* If true, it means the {@link MotionEvent#ACTION_DOWN} happened but
* {@link MotionEvent#ACTION_UP} not yet.
*/
private boolean mStartTouching = false;
/**
* if true, the {@link OnSelectIndexItemListener#onSelectIndexItem(int,String)}
* will not be called until the finger up.
* if false, it will be called when the finger down, up and move.
*/
private boolean mLazyRespond = false;
/**
* the position of the side bar, default is {@link #POSITION_RIGHT}.
* You can set it to {@link #POSITION_LEFT} for people who use phone with left hand.
*/
private int mSideBarPosition;
public static final int POSITION_RIGHT = 0;
public static final int POSITION_LEFT = 1;
/**
* the alignment of items, default is {@link #TEXT_ALIGN_CENTER}.
*/
private int mTextAlignment;
public static final int TEXT_ALIGN_CENTER = 0;
public static final int TEXT_ALIGN_LEFT = 1;
public static final int TEXT_ALIGN_RIGHT = 2;
/**
* observe the current selected index item
*/
private OnSelectIndexItemListener onSelectIndexItemListener;
/**
* the baseline of the first index item text to draw
*/
private float mFirstItemBaseLineY;
/**
* for {@link #dp2px(int)} and {@link #sp2px(int)}
*/
private DisplayMetrics mDisplayMetrics;
public EasySideBar(Context context) {
this(context, null);
}
public EasySideBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public EasySideBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mDisplayMetrics = context.getResources().getDisplayMetrics();
mTextColor = Color.GRAY;
mMaxOffset = dp2px(DEFAULT_MAX_OFFSET);
mSideBarPosition = POSITION_RIGHT;
mTextAlignment = TEXT_ALIGN_CENTER;
/*TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.WaveSideBar);
mLazyRespond = typedArray.getBoolean(R.styleable.WaveSideBar_sidebar_lazy_respond, false);
mTextColor = typedArray.getColor(R.styleable.WaveSideBar_sidebar_text_color, Color.GRAY);
mMaxOffset = typedArray.getDimension(R.styleable.WaveSideBar_sidebar_max_offset, dp2px(DEFAULT_MAX_OFFSET));
mSideBarPosition = typedArray.getInt(R.styleable.WaveSideBar_sidebar_position, POSITION_RIGHT);
mTextAlignment = typedArray.getInt(R.styleable.WaveSideBar_sidebar_text_alignment, TEXT_ALIGN_CENTER);
typedArray.recycle();*/
mTextSize = sp2px(DEFAULT_TEXT_SIZE);
mIndexItems = DEFAULT_INDEX_ITEMS;
initPaint();
}
private void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(mTextColor);
mPaint.setTextSize(mTextSize);
switch (mTextAlignment) {
case TEXT_ALIGN_CENTER: mPaint.setTextAlign(Paint.Align.CENTER); break;
case TEXT_ALIGN_LEFT: mPaint.setTextAlign(Paint.Align.LEFT); break;
case TEXT_ALIGN_RIGHT: mPaint.setTextAlign(Paint.Align.RIGHT); break;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
MaxHeight = MeasureSpec.getSize(heightMeasureSpec);
MaxWidth = MeasureSpec.getSize(widthMeasureSpec);
Paint.FontMetrics fontMetrics = mPaint.getFontMetrics();
mIndexItemHeight = fontMetrics.bottom - fontMetrics.top;
mBarHeight = mIndexItems.length * mIndexItemHeight;
while (mBarHeight >= MaxHeight){
mTextSize--;
mPaint.setTextSize(mTextSize);
fontMetrics = mPaint.getFontMetrics();
mIndexItemHeight = fontMetrics.bottom - fontMetrics.top;
mBarHeight = mIndexItems.length * mIndexItemHeight;
}
// calculate the width of the longest text as the width of side bar
for (String indexItem : mIndexItems) {
mBarWidth = Math.max(mBarWidth, mPaint.measureText(indexItem));
}
float areaLeft = (mSideBarPosition == POSITION_LEFT) ? 0 : (MaxWidth - mBarWidth - getPaddingRight());
float areaRight = (mSideBarPosition == POSITION_LEFT) ? (getPaddingLeft() + areaLeft + mBarWidth) : width;
float areaTop = MaxHeight /2 - mBarHeight/2;
float areaBottom = areaTop + mBarHeight;
mStartTouchingArea.set(
areaLeft,
areaTop,
areaRight,
areaBottom);
// the baseline Y of the first item' text to draw
mFirstItemBaseLineY = (MaxHeight /2 - mIndexItems.length*mIndexItemHeight/2)
+ (mIndexItemHeight/2 - (fontMetrics.descent-fontMetrics.ascent)/2)
- fontMetrics.ascent;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// draw each item
for (int i = 0; i < mIndexItems.length; i++) {
float baseLineY = mFirstItemBaseLineY + mIndexItemHeight*i;
// calculate the scale factor of the item to draw
float scale = getItemScale(i);
int alphaScale = (i == mCurrentIndex) ? (255) : (int) (255 * (1-scale));
mPaint.setAlpha(alphaScale);
mPaint.setTextSize(mTextSize + mTextSize*scale);
float baseLineX = 0f;
if (mSideBarPosition == POSITION_LEFT) {
switch (mTextAlignment) {
case TEXT_ALIGN_CENTER:
baseLineX = getPaddingLeft() + mBarWidth/2 + mMaxOffset*scale;
break;
case TEXT_ALIGN_LEFT:
baseLineX = getPaddingLeft() + mMaxOffset*scale;
break;
case TEXT_ALIGN_RIGHT:
baseLineX = getPaddingLeft() + mBarWidth + mMaxOffset*scale;
break;
}
} else {
switch (mTextAlignment) {
case TEXT_ALIGN_CENTER:
baseLineX = getWidth() - getPaddingRight() - mBarWidth/2 - mMaxOffset*scale;
break;
case TEXT_ALIGN_RIGHT:
baseLineX = getWidth() - getPaddingRight() - mMaxOffset*scale;
break;
case TEXT_ALIGN_LEFT:
baseLineX = getWidth() - getPaddingRight() - mBarWidth - mMaxOffset*scale;
break;
}
}
// draw
canvas.drawText(
mIndexItems[i], //item text to draw
baseLineX, //baseLine X
baseLineY, // baseLine Y
mPaint);
}
// reset paint
mPaint.setAlpha(255);
mPaint.setTextSize(mTextSize);
}
/**
* calculate the scale factor of the item to draw
*
* @param index the index of the item in array {@link #mIndexItems}
* @return the scale factor of the item to draw
*/
private float getItemScale(int index) {
float scale = 0;
if (mCurrentIndex != -1) {
float distance = Math.abs(mCurrentY - (mIndexItemHeight*index+mIndexItemHeight/2)) / mIndexItemHeight;
scale = 1 - distance*distance/16;
scale = Math.max(scale, 0);
}
return scale;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mIndexItems.length == 0) {
return super.onTouchEvent(event);
}
float eventY = event.getY();
float eventX = event.getX();
mCurrentIndex = getSelectedIndex(eventY);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mStartTouchingArea.contains(eventX, eventY)) {
mStartTouching = true;
if (!mLazyRespond && onSelectIndexItemListener != null) {
onSelectIndexItemListener.onSelectIndexItem(mCurrentIndex,mIndexItems[mCurrentIndex]);
}
invalidate();
return true;
} else {
mCurrentIndex = -1;
return false;
}
case MotionEvent.ACTION_MOVE:
if (mStartTouching && !mLazyRespond && onSelectIndexItemListener != null) {
onSelectIndexItemListener.onSelectIndexItem(mCurrentIndex,mIndexItems[mCurrentIndex]);
}
invalidate();
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mLazyRespond && onSelectIndexItemListener != null) {
onSelectIndexItemListener.onSelectIndexItem(mCurrentIndex,mIndexItems[mCurrentIndex]);
}
mCurrentIndex = -1;
mStartTouching = false;
invalidate();
return true;
}
return super.onTouchEvent(event);
}
private int getSelectedIndex(float eventY) {
mCurrentY = eventY - (getHeight()/2 - mBarHeight /2);
if (mCurrentY <= 0) {
return 0;
}
int index = (int) (mCurrentY / this.mIndexItemHeight);
if (index >= this.mIndexItems.length) {
index = this.mIndexItems.length - 1;
}
return index;
}
private float dp2px(int dp) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, this.mDisplayMetrics);
}
private float sp2px(int sp) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, this.mDisplayMetrics);
}
//Customize
public void setIndexItems(String[] indexItems) {
this.mIndexItems = indexItems;
requestLayout();
}
public void setTextColor(int color) {
this.mTextColor = color;
mPaint.setColor(color);
invalidate();
}
public void setPosition(int position) {
if (position != POSITION_RIGHT && position != POSITION_LEFT) {
throw new IllegalArgumentException("the position must be POSITION_RIGHT or POSITION_LEFT");
}
mSideBarPosition = position;
requestLayout();
}
public void setMaxOffset(int offset) {
mMaxOffset = dp2px(offset);
invalidate();
}
public void setLazyRespond(boolean lazyRespond) {
mLazyRespond = lazyRespond;
}
public void setTextAlign(int align) {
if (mTextAlignment == align) {
return;
}
switch (align) {
case TEXT_ALIGN_CENTER: mPaint.setTextAlign(Paint.Align.CENTER); break;
case TEXT_ALIGN_LEFT: mPaint.setTextAlign(Paint.Align.LEFT); break;
case TEXT_ALIGN_RIGHT: mPaint.setTextAlign(Paint.Align.RIGHT); break;
default:
throw new IllegalArgumentException(
"the alignment must be TEXT_ALIGN_CENTER, TEXT_ALIGN_LEFT or TEXT_ALIGN_RIGHT");
}
mTextAlignment = align;
invalidate();
}
public void setOnSelectIndexItemListener(OnSelectIndexItemListener onSelectIndexItemListener) {
this.onSelectIndexItemListener = onSelectIndexItemListener;
}
public interface OnSelectIndexItemListener {
void onSelectIndexItem(int index, String indexValue);
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/lib/EditTextWithDel.java
================================================
package com.esaysidebar.lib;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.EditText;
import com.esaysidebar.R;
/**
* @author: xiaolijuan
* @projectName: SelectCityDome
* @date: 2016-03-01
* @time: 15:59
*/
public class EditTextWithDel extends EditText {
private final static String TAG = "EditTextWithDel";
private Drawable imgInable;
private Drawable imgAble;
private Context mContext;
public EditTextWithDel(Context context) {
super(context);
mContext = context;
init();
}
public EditTextWithDel(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
init();
}
public EditTextWithDel(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
init();
}
private void init() {
imgAble = mContext.getResources().getDrawable(
R.mipmap.icon_delete_gray);
addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
setDrawable();
}
});
setDrawable();
}
private void setDrawable() {
if (length() < 1) {
setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
} else {
setCompoundDrawablesWithIntrinsicBounds(null, null, imgAble, null);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (imgAble != null && event.getAction() == MotionEvent.ACTION_UP) {
int eventX = (int) event.getRawX();
int eventY = (int) event.getRawY();
Log.e(TAG, "eventX = " + eventX + "; eventY = " + eventY);
Rect rect = new Rect();
getGlobalVisibleRect(rect);
rect.left = rect.right - 50;
if (rect.contains(eventX, eventY))
setText("");
}
return super.onTouchEvent(event);
}
@Override
protected void finalize() throws Throwable {
super.finalize();
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/utils/PinyinComparator.java
================================================
package com.esaysidebar.utils;
import com.esaysidebar.bean.CitySortModel;
import java.util.Comparator;
/**
* 用来对ListView中的数据根据A-Z进行排序,前面两个if判断主要是将不是以汉字开头的数据放在后面
*/
public class PinyinComparator implements Comparator {
public int compare(CitySortModel o1, CitySortModel o2) {
//这里主要是用来对ListView里面的数据根据ABCDEFG...来排序
if (o1.getSortLetters().equals("@") || o2.getSortLetters().equals("#")) {
return -1;
} else if (o1.getSortLetters().equals("#") || o2.getSortLetters().equals("@")) {
return 1;
} else {
return o1.getSortLetters().compareTo(o2.getSortLetters());
}
}
}
================================================
FILE: easysidebar/src/main/java/com/esaysidebar/utils/PinyinUtils.java
================================================
package com.esaysidebar.utils;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
/**
* @author:
* @description:
* @projectName: SelectCityDome
* @date: 2016-03-01
* @time: 15:45
*/
public class PinyinUtils {
/**
*
* @param chines
* @return
*/
public static String getAlpha(String chines) {
String pinyinName = "";
char[] nameChar = chines.toCharArray();
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < nameChar.length; i++) {
if (nameChar[i] > 128) {
try {
pinyinName += PinyinHelper.toHanyuPinyinStringArray(
nameChar[i], defaultFormat)[0].charAt(0);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} else {
pinyinName += nameChar[i];
}
}
return pinyinName;
}
/**
*
* string's chinese to pinying ,english string no change
*
* @param inputString
* @return
*/
public static String getPingYin(String inputString) {
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
String output = "";
if (inputString != null && inputString.length() > 0
&& !"null".equals(inputString)) {
char[] input = inputString.trim().toCharArray();
try {
for (int i = 0; i < input.length; i++) {
if (Character.toString(input[i]).matches(
"[\\u4E00-\\u9FA5]+")) {
String[] temp = PinyinHelper.toHanyuPinyinStringArray(
input[i], format);
output += temp[0];
} else
output += Character.toString(input[i]);
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} else {
return "*";
}
return output;
}
/**
*c
*
* @param chines
* @return
*/
public static String converterToFirstSpell(String chines) {
String pinyinName = "";
char[] nameChar = chines.toCharArray();
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < nameChar.length; i++) {
if (nameChar[i] > 128) {
try {
pinyinName += PinyinHelper.toHanyuPinyinStringArray(
nameChar[i], defaultFormat)[0].charAt(0);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} else {
pinyinName += nameChar[i];
}
}
return pinyinName;
}
}
================================================
FILE: easysidebar/src/main/res/drawable/edit_background.xml
================================================
================================================
FILE: easysidebar/src/main/res/drawable/select_btn_white_gray.xml
================================================
-
-
================================================
FILE: easysidebar/src/main/res/drawable/selector_btn_press.xml
================================================
================================================
FILE: easysidebar/src/main/res/layout/activity_sort_city.xml
================================================
================================================
FILE: easysidebar/src/main/res/layout/gridview_item.xml
================================================
================================================
FILE: easysidebar/src/main/res/layout/headview_hotcity.xml
================================================
================================================
FILE: easysidebar/src/main/res/layout/headview_loaction.xml
================================================
================================================
FILE: easysidebar/src/main/res/layout/item_select_city.xml
================================================
================================================
FILE: easysidebar/src/main/res/values/arrays.xml
================================================
- %#S乱码
- 北京市
- 天津市
- 上海市
- 重庆市
- 石家庄
- 唐山市
- 秦皇岛
- 邯郸市
- 邢台市
- 保定市
- 张家口
- 承德市
- 沧州市
- 廊坊市
- 衡水市
- 太原市
- 大同市
- 阳泉市
- 长治市
- 晋城市
- 朔州市
- 晋中市
- 运城市
- 忻州市
- 临汾市
- 吕梁市
- 南京市
- 无锡市
- 徐州市
- 常州市
- 苏州市
- 南通市
- 连云港
- 淮安市
- 盐城市
- 扬州市
- 镇江市
- 泰州市
- 宿迁市
- 杭州市
- 宁波市
- 温州市
- 嘉兴市
- 湖州市
- 绍兴市
- 金华市
- 衢州市
- 舟山市
- 台州市
- 丽水市
- 合肥市
- 芜湖市
- 蚌埠市
- 淮南市
- 马鞍山
- 淮北市
- 铜陵市
- 安庆市
- 黄山市
- 滁州市
- 阜阳市
- 宿州市
- 巢湖市
- 六安市
- 毫州市
- 池州市
- 宣城市
- 福州市
- 厦门市
- 莆田市
- 三明市
- 泉州市
- 漳州市
- 南平市
- 龙岩市
- 宁德市
- 南昌市
- 景德镇
- 萍乡市
- 九江市
- 新余市
- 鹰潭市
- 赣州市
- 吉安市
- 宜春市
- 抚州市
- 上饶市
- 济南市
- 青岛市
- 淄博市
- 枣庄市
- 东营市
- 烟台市
- 潍坊市
- 济宁市
- 泰安市
- 威海市
- 日照市
- 莱芜市
- 临沂市
- 德州市
- 聊城市
- 滨州市
- 菏泽市
- 郑州市
- 开封市
- 洛阳市
- 平顶山
- 安阳市
- 鹤壁市
- 新乡市
- 焦作市
- 濮阳市
- 许昌市
- 漯河市
- 三门峡
- 南阳市
- 商丘市
- 信阳市
- 周口市
- 驻马店
- 武汉市
- 黄石市
- 十堰市
- 宜昌市
- 襄樊市
- 鄂州市
- 荆门市
- 孝感市
- 荆州市
- 黄冈市
- 咸宁市
- 随州市
- 神农架
- 恩施土家族苗族自治州
- 长沙市
- 株洲市
- 湘潭市
- 衡阳市
- 邵阳市
- 岳阳市
- 常德市
- 张家界
- 益阳市
- 永州市
- 怀化市
- 娄底市
- 郴州市
- 湘西土家族苗族自治州
- 广州市
- 韶关市
- 深圳市
- 珠海市
- 汕头市
- 佛山市
- 江门市
- 湛江市
- 茂名市
- 肇庆市
- 惠州市
- 梅州市
- 汕尾市
- 河源市
- 阳江市
- 清远市
- 东莞市
- 中山市
- 潮州市
- 揭阳市
- 云浮市
- 沈阳市
- 大连市
- 鞍山市
- 抚顺市
- 本溪市
- 丹东市
- 锦州市
- 营口市
- 阜新市
- 辽阳市
- 盘锦市
- 铁岭市
- 朝阳市
- 葫芦岛
- 长春市
- 吉林市
- 四平市
- 辽源市
- 通化市
- 白山市
- 松原市
- 白城市
- 延边朝鲜族自治区市
- 哈尔滨
- 齐齐哈尔市
- 鸡西市
- 鹤岗市
- 双鸭山
- 大庆市
- 伊春市
- 佳木斯
- 七台河
- 牡丹江
- 黑河市
- 绥化市
- 大兴安岭地区
- 南宁市
- 柳州市
- 桂林市
- 梧州市
- 北海市
- 防城港
- 钦州市
- 贵港市
- 玉林市
- 百色市
- 贺州市
- 河池市
- 来宾市
- 崇左市
- 海口市
- 三亚市
- 台北市
- 台南市
- 高雄市
- 成都市
- 自贡市
- 攀枝花
- 泸州市
- 德阳市
- 绵阳市
- 广元市
- 遂宁市
- 内江市
- 乐山市
- 南充市
- 眉山市
- 宜宾市
- 广安市
- 达州市
- 雅安市
- 巴中市
- 资阳市
- 阿坝藏族羌族自治州
- 甘孜藏族自治州
- 凉山彝族自治州
- 贵阳市
- 六盘水
- 遵义市
- 安顺市
- 铜仁地
- 黔西南布依族苗族自治州
- 毕节地
- 黔东南苗族侗族自治州
- 黔南布依族苗族自治州
- 昆明市
- 曲靖市
- 玉溪市
- 宝山市
- 邵通市
- 丽江市
- 思茅市
- 临沧市
- 楚雄彝族自治州
- 红河哈尼族彝族自治州
- 文山壮族苗族自治州
- 西双版纳傣族自治州
- 大理白族自治州
- 德宏傣族景颇族自治州
- 怒江傈僳族自治州
- 迪庆藏族自治州
- 拉萨市
- 西安市
- 铜川市
- 宝鸡市
- 咸阳市
- 渭南市
- 延安市
- 汉中市
- 榆林市
- 安康市
- 商洛市
- 兰州市
- 嘉峪关
- 金昌市
- 白银市
- 天水市
- 武威市
- 张掖市
- 平凉市
- 酒泉市
- 庆阳市
- 定西市
- 西宁市
- 海东地区
- 海北藏族自治州
- 黄南藏族自治州市
- 海南藏族自治州
- 果洛藏族自治州
- 玉树藏族自治州
- 海西蒙古族藏族自治州
- 银川市
- 石嘴山
- 吴忠市
- 固原市
- 中卫市
- 呼和浩特市
- 包头市
- 乌海市
- 赤峰市
- 通辽市
- 鄂尔多斯市
- 呼伦贝尔市
- 巴彦卓尔市
- 乌兰察布市
- 兴安盟
- 乌鲁木齐市
- 克拉玛依市
- 吐鲁番地区
- 哈密地区
- 昌吉回族自治州
- 博尔塔拉蒙古自治州
- 巴音郭楞蒙古自治州
- 阿克苏地区
- 克孜勒苏柯尔克孜自治州
- 喀什地区
- 和田地区
- 伊犁哈萨克自治州
- 塔城地区
- 阿勒泰地区
- 石河子市
- 阿拉尔市
- 香港特别行政区
- 澳门特别行政区
================================================
FILE: easysidebar/src/main/res/values/color.xml
================================================
#F9F9F9
#F0F0F0
#88AAAAAA
#00000000
================================================
FILE: easysidebar/src/main/res/values/drawables.xml
================================================
- @color/color_background
- @color/color_transparent
- @color/color_gray_transparent
================================================
FILE: easysidebar/src/main/res/values/strings.xml
================================================
EasySideBarLibrary
================================================
FILE: easysidebar/src/main/res/values-w820dp/dimens.xml
================================================
64dp
================================================
FILE: easysidebar/src/test/java/com/demo/ExampleUnitTest.java
================================================
package com.demo;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see Testing documentation
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app', ':easysidebar'