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。 ![EasySideBar.gif](https://github.com/Bigkoo/EasySideBar/blob/master/preview/GIF.gif) ## **使用步骤:** ### 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 ================================================