{"id":13643375,"url":"https://github.com/yuruizhe/CityPicker","last_synced_at":"2025-04-21T01:32:26.603Z","repository":{"id":217102463,"uuid":"92012267","full_name":"yuruizhe/CityPicker","owner":"yuruizhe","description":"一个仿大众点评、美团的城市选择器，使用如同Rx一样优雅，并且UI和城市数据可以自定义","archived":false,"fork":false,"pushed_at":"2018-01-24T06:34:33.000Z","size":1228,"stargazers_count":109,"open_issues_count":2,"forks_count":25,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-09T15:42:30.615Z","etag":null,"topics":["city","citypicker","picker"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuruizhe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-22T04:46:54.000Z","updated_at":"2024-09-26T06:36:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0ff77bb-2e4d-4a02-8aa0-e9ea4417ea12","html_url":"https://github.com/yuruizhe/CityPicker","commit_stats":null,"previous_names":["yuruizhe/citypicker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuruizhe%2FCityPicker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuruizhe%2FCityPicker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuruizhe%2FCityPicker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuruizhe%2FCityPicker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuruizhe","download_url":"https://codeload.github.com/yuruizhe/CityPicker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249982623,"owners_count":21355735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["city","citypicker","picker"],"created_at":"2024-08-02T01:01:46.591Z","updated_at":"2025-04-21T01:32:25.796Z","avatar_url":"https://github.com/yuruizhe.png","language":"Java","funding_links":[],"categories":["选择器(Picker)"],"sub_categories":[],"readme":"CityPicker\n===\n\n[![API](https://img.shields.io/badge/API-14%2B-yellow.svg?style=flat)](https://android-arsenal.com/api?level=14)\u003c/br\u003e\n一个仿大众点评的城市快速选择器，\n最少只需 **一行** 代码即可启动城市选择器，\n支持页面样式修改，多元化自定义\n\nScreenShot\n---\n\n| ![](https://github.com/yuruizhe/CityPicker/blob/master/screenshot/Screenshot_2017-05-22-11-22-58.png) | ![](https://github.com/yuruizhe/CityPicker/blob/master/screenshot/Screenshot_2017-05-22-11-23-08.png) | ![](https://github.com/yuruizhe/CityPicker/blob/master/screenshot/Screenshot_2017-05-22-11-22-45.png) |\n|---|----|:---:|\n\n\nVersion Log\n---\n* ``V0.4.6``\n  * 优化地理位置设置时有时会设置不成功问题\n  * 修复其他若干问题\n  * 修改UI默认主题色\n* ``V0.4.5``\n  * 修改设置位置信息方式，由之前必须在打开页面之前获取位置信息改为允许用户在打开页面后设置位置信息，具体使用方式见 [Step3](#step3)\n  * 简化配置项，不需要在AndroidManifest中再注册Activity，并默认隐藏titlebar\n* ``V0.4.3``\n  * 修复更新数据库表结构后第一次进入会闪退问题\n* ``V0.4.0``\n  * 数据库表结构修改，增加了高德地图citycode\n  * 设置gps城市的api略有改动见  [Step3](#step3)\n* ``V0.3.3``\n  * 紧急修复一个可能导致内存泄漏问题\n  * 优化提高滑动检索效率\n  * 隐藏下拉刷新label\n* ``V0.3.1``\n  * 在搜索框后面添加一个清空搜索框按钮\n  * 修复搜索框中输入空格会搜索出全部城市问题\n  * 修复搜索结果弹出框中文字在不同theme下显示不同颜色问题，现在已统一为黑色\n  * 其他调用时参数合法性校验\n* ``V0.3.0``\n  * 简化api调用形式，修改为Rx形式，见[操作步骤](#use)\n* ``V0.2.2``\n  * 修复进入页面会闪退问题\n  * 修复修改右边滑动索引栏颜色时左边拼音标签颜色未修改问题\n  * 启动城市选择页面时增加一个步骤见  [Step3](#step3)\n* ``V0.1.0``\n  * 初始导入\n\nImport\n---\n###### Maven\n``` xml\n  \u003cdependency\u003e\n  \u003cgroupId\u003ecom.desmond\u003c/groupId\u003e\n  \u003cartifactId\u003eCityPicker\u003c/artifactId\u003e\n  \u003cversion\u003exxx\u003c/version\u003e\n  \u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n``` \n###### Gradle\n``` gradle\ncompile 'com.desmond:CityPicker:xxx'\n```\nWiki\n---\n### Functions\n* 支持自定义基础城市列表（beta）\n* 支持历史点击城市查询\n* 支持自定义热门城市列表\n* 支持选择城市返回对象（目前已经囊括：城市名称，城市code（baidu、高德）等）\n* 提供方法支持页面样式轻度自定义。或继承CityPickerActivity重写部分UI样式\n* 基础数据依赖sqlite提供高效的查询效率\n* 与三方定位库解耦\n* 支持沉浸式状态栏\n\n### Use\n##### Step1\n\n对于Android 6.0需要配置动态权限\u003c/br\u003e\n``` java\nManifest.permission.WRITE_EXTERNAL_STORAGE\n```\n\n##### Step2\n启动城市选择页面及相关自定义配置\n``` java\n        CityPicker.with(getContext())        \n        \n        //是否需要显示当前城市,如果为false那么就隐藏当前城市，并且调用setGpsCityByBaidu()或setGpsCityByAMap()都不会生效，非必选项,默认为true\n        .setUseGpsCity(true)\n\n        //自定义热门城市，输入数据库中的城市id（_id），非必选项，默认为数据库中的热门城市\n        .setHotCitiesId(\"2\", \"9\", \"18\", \"11\", \"66\", \"1\", \"80\", \"49\", \"100\");\n\n        //设置最多显示历史点击城市数量，0为不显示历史城市\n        .setMaxHistory(6);\n\n        // 自定义城市基础数据列表，必须放在项目的assets文件夹下，并且表结构同citypicker项目下的assets中的数据库表结构相同\n        // 该方法当前为beta版本，不推荐使用\n        .setCustomDBName(\"xx.sqlite\");\n\n        // 设置标题栏背景，非必选项\n        .setTitleBarDrawable(...);\n\n        // 设置返回按钮图片，非必选项\n        .setTitleBarBackBtnDrawable(...);\n\n        // 设置搜索框背景，非必选项\n        .setSearchViewDrawable(...);\n\n        // 设置搜索框字体颜色，非必选项\n        .setSearchViewTextColor(...);\n\n        // 设置搜索框字体大小，非必选项\n        .setSearchViewTextSize(...);\n\n        // 设置右边检索栏字体颜色，非必选项\n        .setIndexBarTextColor(...);\n\n        // 设置右边检索栏字体大小，非必选项\n        .setIndexBarTextSize(...);\n\n        // 是否使用沉浸式状态栏，默认使用，非必选项\n        .setUseImmerseBar(true);\n        \n        // 回调\n        .setOnCityPickerCallBack(new IOnCityPickerCheckedCallBack()\n        {\n           @Override\n           public void onCityPickerChecked(BaseCity baseCity)\n           {\n               //获取选择城市编码\n               baseCity.getCodeByBaidu();  //baseCity.getCodeByAMap();//高德code\n        \n               //获取选择城市名称\n               baseCity.getCityName();\n        \n               // 获取选择城市拼音全拼\n               baseCity.getCityPinYin();\n        \n               //获取选择城市拼音首字母\n               baseCity.getCityPYFirst();\n           }\n         })\n         \n        .open();\n      \n ```\n##### Step3\n获取到位置信息后调用该静态方法可以在页面打开后设置当前城市\u003c/br\u003e\n百度定位或高德定位需要自行配置，在这个库中没有集成任何与定位相关的模块\n``` java\n//使用百度定位\nCityPicker.setGpsCityByBaidu(\"南京市\",\"315\");\n\n//高德定位\nCityPicker.setGpsCityByAMap(\"南京市\",\"025\");\n```\n### Be careful\n* 基础数据库名称定义为：**city.sqlite**。在引入的工程中千万不可创建**同名的数据库**，否则可能会发生异常！\n\n* 自定义基础数据库必须重写``city.sqlite``中的``tb_city`` 和 ``tb_history``, 允许增加字段，但不可删除或修改字段\n\n项目中使用了如下三方库，如与你项目中的库冲突，请及时排除\u003c/br\u003e\n```gradle\ndef supportLibraryVersion = '24.2.1'\ndependencies {\n    compile fileTree(dir: 'libs', include: ['*.jar'])\n    testCompile 'junit:junit:4.12'\n    compile \"com.android.support:support-v4:$supportLibraryVersion\"\n    compile \"com.android.support:appcompat-v7:$supportLibraryVersion\"\n    compile \"com.android.support:recyclerview-v7:$supportLibraryVersion\"\n    compile \"com.android.support:design:$supportLibraryVersion\"\n    compile \"com.android.support:gridlayout-v7:$supportLibraryVersion\"\n    compile 'com.gjiazhe:wavesidebar:1.3'\n    compile 'com.squareup.sqlbrite:sqlbrite:1.1.1'\n    compile 'io.reactivex:rxjava:1.2.0'\n    //rx系列\n    compile 'io.reactivex:rxandroid:1.2.1'\n\n    compile 'org.greenrobot:eventbus:3.0.0'\n\n}\n```\n排除示例：\n```gradle\ncompile ('com.desmond:CityPicker:0.3.0' ){\n        exclude group: 'com.android.support'\n        exclude group:'com.squareup.sqlbrite'\n        exclude group:'io.reactivex'\n        exclude group:'io.rxandroid'\n        exclude group:'org.greenrobot'\n    }\n```\n\nDemo\n---\n手机扫描下方二维码下载demo尝鲜\u003c/br\u003e\n![](https://www.pgyer.com/app/qrcode/ecVs)\n\nThanks\n---\n* https://github.com/gjiazhe/WaveSideBar\n* https://github.com/square/sqlbrite\n\nContact author\n---\nQQ 350248823 添加时注明github-citypicker\u003c/br\u003e\n欢迎issues，作者看到后会第一时间回复\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuruizhe%2FCityPicker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuruizhe%2FCityPicker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuruizhe%2FCityPicker/lists"}