├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── findbugs-idea.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── youmu │ │ └── wheelpicker │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── province │ ├── java │ │ └── com │ │ │ └── youmu │ │ │ └── wheelpicker │ │ │ ├── MainActivity.java │ │ │ ├── dialog │ │ │ ├── BaseDialog.java │ │ │ ├── ProvinceCallBack.java │ │ │ └── ProvincehDialog.java │ │ │ └── model │ │ │ └── ProvinceCity.java │ └── res │ │ ├── drawable │ │ ├── province_wheel_bg.xml │ │ └── province_wheel_val.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_main.xml │ │ ├── dialog_province.xml │ │ └── item_view.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_wheel_sel.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── youmu │ └── wheelpicker │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── pic.png ├── settings.gradle └── wheel ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── kankan │ └── wheel │ └── ApplicationTest.java ├── main ├── AndroidManifest.xml ├── java │ └── kankan │ │ └── wheel │ │ └── widget │ │ ├── ItemsRange.java │ │ ├── OnWheelChangedListener.java │ │ ├── OnWheelClickedListener.java │ │ ├── OnWheelScrollListener.java │ │ ├── WheelAdapter.java │ │ ├── WheelRecycle.java │ │ ├── WheelScroller.java │ │ ├── WheelView.java │ │ └── adapters │ │ ├── AbstractWheelAdapter.java │ │ ├── AbstractWheelTextAdapter.java │ │ ├── AdapterWheel.java │ │ ├── ArrayWheelAdapter.java │ │ ├── NumericWheelAdapter.java │ │ └── WheelViewAdapter.java └── res │ ├── drawable │ ├── wheel_bg.xml │ └── wheel_val.xml │ └── values │ └── strings.xml └── test └── java └── kankan └── wheel └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | WheelPicker -------------------------------------------------------------------------------- /.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/findbugs-idea.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 32 | 203 | 216 | 225 | 226 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WheelPicker 2 | 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.youmu.wheelpicker" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | compile 'com.jakewharton:butterknife:7.0.1' 28 | compile 'com.alibaba:fastjson:1.2.7' 29 | compile project(':wheel') 30 | } 31 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/youzehong/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/youmu/wheelpicker/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.youmu.wheelpicker; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/assets/province: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "citys": [ 4 | "北京市" 5 | ], 6 | "province": "北京市" 7 | }, 8 | { 9 | "citys": [ 10 | "上海市" 11 | ], 12 | "province": "上海市" 13 | }, 14 | { 15 | "citys": [ 16 | "天津市" 17 | ], 18 | "province": "天津市" 19 | }, 20 | { 21 | "citys": [ 22 | "重庆市" 23 | ], 24 | "province": "重庆市" 25 | }, 26 | { 27 | "citys": [ 28 | "成都市", 29 | "自贡市", 30 | "攀枝花市", 31 | "泸州市", 32 | "德阳市", 33 | "绵阳市", 34 | "广元市", 35 | "遂宁市", 36 | "内江市", 37 | "乐山市", 38 | "南充市", 39 | "眉山市", 40 | "宜宾市", 41 | "广安市", 42 | "达州市", 43 | "雅安市", 44 | "巴中市", 45 | "资阳市", 46 | "阿坝县", 47 | "甘孜县", 48 | "西昌市" 49 | ], 50 | "province": "四川省" 51 | }, 52 | { 53 | "citys": [ 54 | "贵阳市", 55 | "六盘水市", 56 | "遵义市", 57 | "安顺市", 58 | "毕节市", 59 | "铜仁市", 60 | "凯里市", 61 | "都匀市", 62 | "兴义市", 63 | "黔西县" 64 | ], 65 | "province": "贵州省" 66 | }, 67 | { 68 | "citys": [ 69 | "昆明市", 70 | "大理市", 71 | "曲靖市", 72 | "玉溪市", 73 | "保山市", 74 | "昭通市", 75 | "丽江市", 76 | "思茅市", 77 | "临沧市", 78 | "红河县", 79 | "怒江州", 80 | "文山县", 81 | "景洪市", 82 | "瑞丽市", 83 | "楚雄市", 84 | "迪庆州" 85 | ], 86 | "province": "云南省" 87 | }, 88 | { 89 | "citys": [ 90 | "拉萨市", 91 | "阿里地区", 92 | "昌都地区", 93 | "林芝县", 94 | "那曲地区", 95 | "日喀则市", 96 | "樟木口岸镇" 97 | ], 98 | "province": "西藏" 99 | }, 100 | { 101 | "citys": [ 102 | "郑州市", 103 | "开封市", 104 | "洛阳市", 105 | "平顶山市", 106 | "安阳市", 107 | "鹤壁市", 108 | "新乡市", 109 | "焦作市", 110 | "濮阳市", 111 | "许昌市", 112 | "漯河市", 113 | "三门峡市", 114 | "南阳市", 115 | "商丘市", 116 | "信阳市", 117 | "周口市", 118 | "驻马店市" 119 | ], 120 | "province": "河南省" 121 | }, 122 | { 123 | "citys": [ 124 | "武汉市", 125 | "黄石市", 126 | "十堰市", 127 | "宜昌市", 128 | "襄樊市", 129 | "鄂州市", 130 | "荆门市", 131 | "孝感市", 132 | "荆州市", 133 | "黄冈市", 134 | "咸宁市", 135 | "随州市", 136 | "仙桃市", 137 | "天门市", 138 | "恩施州" 139 | ], 140 | "province": "湖北省" 141 | }, 142 | { 143 | "citys": [ 144 | "长沙市", 145 | "株州市", 146 | "湘潭市", 147 | "衡阳市", 148 | "邵阳市", 149 | "岳阳市", 150 | "常德市", 151 | "张家界市", 152 | "益阳市", 153 | "郴州市", 154 | "永州市", 155 | "怀化市", 156 | "娄底市", 157 | "吉首市" 158 | ], 159 | "province": "湖南省" 160 | }, 161 | { 162 | "citys": [ 163 | "广州市", 164 | "韶关市", 165 | "深圳市", 166 | "珠海市", 167 | "汕头市", 168 | "佛山市", 169 | "江门市", 170 | "湛江市", 171 | "茂名市", 172 | "肇庆市", 173 | "惠州市", 174 | "梅州市", 175 | "汕尾市", 176 | "河源市", 177 | "阳江市", 178 | "清远市", 179 | "东莞市", 180 | "中山市", 181 | "潮州市", 182 | "揭阳市", 183 | "云浮市" 184 | ], 185 | "province": "广东省" 186 | }, 187 | { 188 | "citys": [ 189 | "南宁市", 190 | "柳州市", 191 | "桂林市", 192 | "梧州市", 193 | "北海市", 194 | "防城港市", 195 | "钦州市", 196 | "贵港市", 197 | "玉林市", 198 | "百色市", 199 | "贺州市", 200 | "河池市", 201 | "来宾市", 202 | "崇左市" 203 | ], 204 | "province": "广西省" 205 | }, 206 | { 207 | "citys": [ 208 | "西安市", 209 | "铜川市", 210 | "宝鸡市", 211 | "咸阳市", 212 | "渭南市", 213 | "延安市", 214 | "汉中市", 215 | "榆林市", 216 | "安康市", 217 | "商洛市" 218 | ], 219 | "province": "陕西省" 220 | }, 221 | { 222 | "citys": [ 223 | "兰州市", 224 | "嘉峪关市", 225 | "金昌市", 226 | "白银市", 227 | "天水市", 228 | "武威市", 229 | "张掖市", 230 | "平凉市", 231 | "酒泉市", 232 | "庆阳市", 233 | "定西市", 234 | "陇南市", 235 | "临夏州", 236 | "甘南州" 237 | ], 238 | "province": "甘肃省" 239 | }, 240 | { 241 | "citys": [ 242 | "西宁市", 243 | "海东地区", 244 | "海北藏族自治州", 245 | "黄南藏族自治州", 246 | "海南藏族自治州", 247 | "果洛藏族自治州", 248 | "玉树藏族自治州", 249 | "海西蒙古族藏族自治州" 250 | ], 251 | "province": "青海省" 252 | }, 253 | { 254 | "citys": [ 255 | "银川市", 256 | "石嘴山市", 257 | "吴忠市", 258 | "固原市", 259 | "中卫市" 260 | ], 261 | "province": "宁夏" 262 | }, 263 | { 264 | "citys": [ 265 | "乌鲁木齐市", 266 | "克拉玛依市", 267 | "吐鲁番市", 268 | "哈密市", 269 | "昌吉市", 270 | "博乐市", 271 | "库尔勒市", 272 | "阿克苏市", 273 | "克孜勒苏柯尔克孜自治州", 274 | "喀什市", 275 | "和田市", 276 | "伊宁市", 277 | "塔城市", 278 | "阿勒泰市", 279 | "奎屯市", 280 | "石河子市" 281 | ], 282 | "province": "新疆" 283 | }, 284 | { 285 | "citys": [ 286 | "石家庄市", 287 | "唐山市", 288 | "秦皇岛市", 289 | "邯郸市", 290 | "邢台市", 291 | "保定市", 292 | "张家口市", 293 | "承德市", 294 | "沧州市", 295 | "廊坊市", 296 | "衡水市" 297 | ], 298 | "province": "河北省" 299 | }, 300 | { 301 | "citys": [ 302 | "太原市", 303 | "大同市", 304 | "阳泉市", 305 | "长治市", 306 | "晋城市", 307 | "朔州市", 308 | "晋中市", 309 | "运城市", 310 | "忻州市", 311 | "临汾市", 312 | "吕梁市" 313 | ], 314 | "province": "山西省" 315 | }, 316 | { 317 | "citys": [ 318 | "呼和浩特市", 319 | "包头市", 320 | "乌海市", 321 | "赤峰市", 322 | "通辽市", 323 | "鄂尔多斯市", 324 | "呼伦贝尔市", 325 | "巴彦淖尔盟", 326 | "乌兰察布盟", 327 | "兴安盟", 328 | "锡林郭勒盟", 329 | "阿拉善盟" 330 | ], 331 | "province": "内蒙古" 332 | }, 333 | { 334 | "citys": [ 335 | "南京市", 336 | "无锡市", 337 | "徐州市", 338 | "常州市", 339 | "苏州市", 340 | "南通市", 341 | "连云港市", 342 | "淮安市", 343 | "盐城市", 344 | "扬州市", 345 | "镇江市", 346 | "泰州市", 347 | "宿迁市" 348 | ], 349 | "province": "江苏省" 350 | }, 351 | { 352 | "citys": [ 353 | "杭州市", 354 | "宁波市", 355 | "温州市", 356 | "嘉兴市", 357 | "湖州市", 358 | "绍兴市", 359 | "金华市", 360 | "衢州市", 361 | "舟山市", 362 | "台州市", 363 | "丽水市" 364 | ], 365 | "province": "浙江省" 366 | }, 367 | { 368 | "citys": [ 369 | "合肥市", 370 | "芜湖市", 371 | "蚌埠市", 372 | "淮南市", 373 | "马鞍山市", 374 | "淮北市", 375 | "铜陵市", 376 | "安庆市", 377 | "黄山市", 378 | "滁州市", 379 | "阜阳市", 380 | "宿州市", 381 | "巢湖市", 382 | "六安市", 383 | "亳州市", 384 | "池州市", 385 | "宣城市" 386 | ], 387 | "province": "安徽省" 388 | }, 389 | { 390 | "citys": [ 391 | "福州市", 392 | "厦门市", 393 | "莆田市", 394 | "三明市", 395 | "泉州市", 396 | "漳州市", 397 | "南平市", 398 | "龙岩市", 399 | "宁德市" 400 | ], 401 | "province": "福建省" 402 | }, 403 | { 404 | "citys": [ 405 | "南昌市", 406 | "景德镇市", 407 | "萍乡市", 408 | "九江市", 409 | "新余市", 410 | "鹰潭市", 411 | "赣州市", 412 | "吉安市", 413 | "宜春市", 414 | "抚州市", 415 | "上饶市" 416 | ], 417 | "province": "江西省" 418 | }, 419 | { 420 | "citys": [ 421 | "济南市", 422 | "青岛市", 423 | "淄博市", 424 | "枣庄市", 425 | "东营市", 426 | "烟台市", 427 | "潍坊市", 428 | "济宁市", 429 | "泰安市", 430 | "威海市", 431 | "日照市", 432 | "莱芜市", 433 | "临沂市", 434 | "德州市", 435 | "聊城市", 436 | "滨州市", 437 | "菏泽市" 438 | ], 439 | "province": "山东省" 440 | }, 441 | { 442 | "citys": [ 443 | "沈阳市", 444 | "大连市", 445 | "鞍山市", 446 | "抚顺市", 447 | "本溪市", 448 | "丹东市", 449 | "锦州市", 450 | "营口市", 451 | "阜新市", 452 | "辽阳市", 453 | "盘锦市", 454 | "铁岭市", 455 | "朝阳市", 456 | "葫芦岛市" 457 | ], 458 | "province": "辽宁省" 459 | }, 460 | { 461 | "citys": [ 462 | "长春市", 463 | "吉林市", 464 | "四平市", 465 | "辽源市", 466 | "通化市", 467 | "白山市", 468 | "松原市", 469 | "白城市", 470 | "延吉市" 471 | ], 472 | "province": "吉林省" 473 | }, 474 | { 475 | "citys": [ 476 | "哈尔滨市", 477 | "齐齐哈尔市", 478 | "鸡西市", 479 | "鹤岗市", 480 | "双鸭山市", 481 | "大庆市", 482 | "伊春市", 483 | "佳木斯市", 484 | "七台河市", 485 | "牡丹江市", 486 | "黑河市", 487 | "绥化市", 488 | "大兴安岭地区" 489 | ], 490 | "province": "黑龙江省" 491 | }, 492 | { 493 | "citys": [ 494 | "海口市", 495 | "儋州市", 496 | "三亚市" 497 | ], 498 | "province": "海南省" 499 | } 500 | ] -------------------------------------------------------------------------------- /app/src/main/java/com/youmu/wheelpicker/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.youmu.wheelpicker; 2 | 3 | import android.os.Bundle; 4 | import android.support.design.widget.FloatingActionButton; 5 | import android.support.design.widget.Snackbar; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.Menu; 9 | import android.view.MenuItem; 10 | import android.view.View; 11 | import android.widget.Button; 12 | 13 | import com.youmu.wheelpicker.dialog.ProvinceCallBack; 14 | import com.youmu.wheelpicker.dialog.ProvincehDialog; 15 | 16 | import butterknife.Bind; 17 | import butterknife.ButterKnife; 18 | import butterknife.OnClick; 19 | 20 | public class MainActivity extends AppCompatActivity implements ProvinceCallBack{ 21 | 22 | @Bind(R.id.button_province) 23 | Button buttonProvince; 24 | private String mProvince = "北京市";; 25 | private String mCity = "北京市"; 26 | 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_main); 32 | ButterKnife.bind(this); 33 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 34 | setSupportActionBar(toolbar); 35 | 36 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 37 | fab.setOnClickListener(new View.OnClickListener() { 38 | @Override 39 | public void onClick(View view) { 40 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 41 | .setAction("Action", null).show(); 42 | } 43 | }); 44 | } 45 | 46 | @OnClick(R.id.button_province) 47 | public void provinceClick(View v) { 48 | ProvincehDialog branchDialog = ProvincehDialog.newInstance(); 49 | branchDialog.setAddress(mProvince, mCity); 50 | branchDialog.show(getSupportFragmentManager()); 51 | } 52 | 53 | @Override 54 | public boolean onCreateOptionsMenu(Menu menu) { 55 | // Inflate the menu; this adds items to the action bar if it is present. 56 | getMenuInflater().inflate(R.menu.menu_main, menu); 57 | return true; 58 | } 59 | 60 | @Override 61 | public boolean onOptionsItemSelected(MenuItem item) { 62 | // Handle action bar item clicks here. The action bar will 63 | // automatically handle clicks on the Home/Up button, so long 64 | // as you specify a parent activity in AndroidManifest.xml. 65 | int id = item.getItemId(); 66 | 67 | //noinspection SimplifiableIfStatement 68 | if (id == R.id.action_settings) { 69 | return true; 70 | } 71 | 72 | return super.onOptionsItemSelected(item); 73 | } 74 | 75 | @Override 76 | public void onWhellFinish(String province, String city) { 77 | mProvince = province; 78 | mCity = city; 79 | buttonProvince.setText(province + city); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /app/src/main/java/com/youmu/wheelpicker/dialog/BaseDialog.java: -------------------------------------------------------------------------------- 1 | package com.youmu.wheelpicker.dialog; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.content.Context; 6 | import android.os.Bundle; 7 | import android.support.annotation.NonNull; 8 | import android.support.v4.app.DialogFragment; 9 | import android.support.v4.app.FragmentManager; 10 | import android.view.View; 11 | 12 | import com.youmu.wheelpicker.R; 13 | 14 | import java.lang.ref.WeakReference; 15 | 16 | import butterknife.ButterKnife; 17 | 18 | public abstract class BaseDialog extends DialogFragment { 19 | 20 | protected Context mContext; 21 | 22 | private static WeakReference dialogWeakReference; 23 | 24 | @Override 25 | public void onAttach(Activity activity) { 26 | super.onAttach(activity); 27 | mContext = activity; 28 | } 29 | 30 | public static void dissmissDialog() { 31 | try { 32 | BaseDialog dialog = dialogWeakReference.get(); 33 | if (dialog != null && dialog.isAdded()) { 34 | dialog.dismiss(); 35 | dialog = null; 36 | } 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | 42 | @NonNull 43 | @Override 44 | public Dialog onCreateDialog(Bundle savedInstanceState) { 45 | Dialog dialog = new Dialog(getActivity(), onGetStyle()); 46 | dialog.setCanceledOnTouchOutside(true); 47 | dialog.setCancelable(true); 48 | View view = View.inflate(getActivity(), onGetDialogViewId(), null); 49 | dialog.setContentView(view); 50 | ButterKnife.bind(this, view); 51 | onDialogCreated(dialog); 52 | return dialog; 53 | } 54 | 55 | protected abstract void onDialogCreated(Dialog dialog); 56 | 57 | protected abstract int onGetDialogViewId(); 58 | 59 | protected int onGetStyle() { 60 | return R.style.custom_dialog; 61 | } 62 | 63 | public void show(FragmentManager fragmentManager) { 64 | dialogWeakReference = new WeakReference(this); 65 | show(fragmentManager, "dialog"); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/youmu/wheelpicker/dialog/ProvinceCallBack.java: -------------------------------------------------------------------------------- 1 | package com.youmu.wheelpicker.dialog; 2 | 3 | public interface ProvinceCallBack { 4 | 5 | public void onWhellFinish(String province, String city); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/youmu/wheelpicker/dialog/ProvincehDialog.java: -------------------------------------------------------------------------------- 1 | package com.youmu.wheelpicker.dialog; 2 | 3 | import android.app.Activity; 4 | import android.app.Dialog; 5 | import android.content.Context; 6 | import android.graphics.Color; 7 | import android.text.TextUtils; 8 | import android.util.DisplayMetrics; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.TextView; 12 | 13 | import com.alibaba.fastjson.JSON; 14 | import com.youmu.wheelpicker.R; 15 | import com.youmu.wheelpicker.model.ProvinceCity; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.io.InputStreamReader; 21 | import java.io.StringWriter; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | import butterknife.Bind; 26 | import butterknife.OnClick; 27 | import kankan.wheel.widget.OnWheelChangedListener; 28 | import kankan.wheel.widget.OnWheelScrollListener; 29 | import kankan.wheel.widget.WheelView; 30 | import kankan.wheel.widget.adapters.AbstractWheelTextAdapter; 31 | 32 | public class ProvincehDialog extends BaseDialog { 33 | @Bind(R.id.wv_province) 34 | WheelView mWvProvince; 35 | @Bind(R.id.wv_city) 36 | WheelView mWvCity; 37 | 38 | private int maxsize = 24; 39 | private int minsize = 14; 40 | private ArrayList arrProvinces = new ArrayList(); 41 | private ArrayList arrCitys = new ArrayList(); 42 | private AddressTextAdapter provinceAdapter; 43 | private AddressTextAdapter cityAdapter; 44 | private String strProvince = "北京市"; 45 | private String strCity = "北京市"; 46 | private int selColor; 47 | private int unSelColor; 48 | private ProvinceCallBack mListener; 49 | private List provinceCityLists; 50 | 51 | public static ProvincehDialog newInstance() { 52 | ProvincehDialog dialog = new ProvincehDialog(); 53 | return dialog; 54 | } 55 | 56 | @Override 57 | public void onAttach(Activity activity) { 58 | super.onAttach(activity); 59 | mListener = (ProvinceCallBack) activity; 60 | } 61 | 62 | @Override 63 | protected int onGetStyle() { 64 | return R.style.transparent_dialog; 65 | } 66 | 67 | @OnClick(R.id.layout_wheel_top) 68 | public void topClick(View v) { 69 | dissmissDialog(); 70 | } 71 | 72 | @OnClick(R.id.iv_wheel_ok) 73 | public void okClick(View v) { 74 | strProvince = (String) provinceAdapter.getItemText(mWvProvince.getCurrentItem()); 75 | strCity = (String) cityAdapter.getItemText(mWvCity.getCurrentItem()); 76 | mListener.onWhellFinish(strProvince, strCity); 77 | dismiss(); 78 | } 79 | 80 | private void initData() { 81 | try { 82 | String json = readString(mContext.getAssets().open("province")); 83 | provinceCityLists = JSON.parseArray(json, ProvinceCity.class); 84 | if (provinceCityLists != null && !provinceCityLists.isEmpty()) { 85 | for (ProvinceCity provinceCity : provinceCityLists) { 86 | arrProvinces.add(provinceCity.getProvince()); 87 | } 88 | } 89 | } catch (IOException e) { 90 | e.printStackTrace(); 91 | } 92 | } 93 | 94 | @Override 95 | public void onStart() { 96 | super.onStart(); 97 | DisplayMetrics dm = new DisplayMetrics(); 98 | getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); 99 | getDialog().getWindow().setLayout(dm.widthPixels, getDialog().getWindow().getAttributes().height); 100 | } 101 | 102 | @SuppressWarnings("deprecation") 103 | @Override 104 | protected void onDialogCreated(Dialog dialog) { 105 | selColor = getResources().getColor(R.color.color_wheel_sel); 106 | unSelColor = getResources().getColor(R.color.color_wheel_unsel); 107 | initData(); 108 | provinceAdapter = new AddressTextAdapter(mContext, arrProvinces, getProvinceItem(strProvince), maxsize, minsize); 109 | mWvProvince.setVisibleItems(5); 110 | mWvProvince.setViewAdapter(provinceAdapter); 111 | mWvProvince.setCurrentItem(getProvinceItem(strProvince)); 112 | mWvProvince.setShadowColor(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT); 113 | mWvProvince.setWheelBackground(R.drawable.province_wheel_bg); 114 | mWvProvince.setWheelForeground(R.drawable.province_wheel_val); 115 | mWvProvince.post(new Runnable() { 116 | 117 | @Override 118 | public void run() { 119 | String currentText = (String) provinceAdapter.getItemText(mWvProvince.getCurrentItem()); 120 | setTextviewSize(currentText, provinceAdapter); 121 | } 122 | }); 123 | 124 | initCitys(strProvince); 125 | cityAdapter = new AddressTextAdapter(mContext, arrCitys, getCityItem(strCity), maxsize, minsize); 126 | mWvCity.setVisibleItems(5); 127 | mWvCity.setViewAdapter(cityAdapter); 128 | mWvCity.setCurrentItem(getCityItem(strCity)); 129 | mWvCity.setShadowColor(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT); 130 | mWvCity.setWheelBackground(R.drawable.province_wheel_bg); 131 | mWvCity.setWheelForeground(R.drawable.province_wheel_val); 132 | mWvCity.post(new Runnable() { 133 | 134 | @Override 135 | public void run() { 136 | String currentText = (String) cityAdapter.getItemText(mWvCity.getCurrentItem()); 137 | setTextviewSize(currentText, cityAdapter); 138 | } 139 | }); 140 | 141 | mWvProvince.addChangingListener(new OnWheelChangedListener() { 142 | 143 | @Override 144 | public void onChanged(WheelView wheel, int oldValue, int newValue) { 145 | String currentText = (String) provinceAdapter.getItemText(wheel.getCurrentItem()); 146 | strProvince = currentText; 147 | setTextviewSize(currentText, provinceAdapter); 148 | initCitys(currentText); 149 | cityAdapter = new AddressTextAdapter(mContext, arrCitys, 0, maxsize, minsize); 150 | mWvCity.setVisibleItems(5); 151 | mWvCity.setCurrentItem(0); 152 | String currentCityText = (String) cityAdapter.getItemText(mWvCity.getCurrentItem()); 153 | setTextviewSize(currentCityText, cityAdapter); 154 | mWvCity.setViewAdapter(cityAdapter); 155 | } 156 | }); 157 | 158 | mWvProvince.addScrollingListener(new OnWheelScrollListener() { 159 | 160 | @Override 161 | public void onScrollingStarted(WheelView wheel) { 162 | } 163 | 164 | @Override 165 | public void onScrollingFinished(WheelView wheel) { 166 | String currentText = (String) provinceAdapter.getItemText(wheel.getCurrentItem()); 167 | setTextviewSize(currentText, provinceAdapter); 168 | } 169 | }); 170 | 171 | mWvCity.addChangingListener(new OnWheelChangedListener() { 172 | 173 | @Override 174 | public void onChanged(WheelView wheel, int oldValue, int newValue) { 175 | String currentText = (String) cityAdapter.getItemText(wheel.getCurrentItem()); 176 | strCity = currentText; 177 | setTextviewSize(currentText, cityAdapter); 178 | } 179 | }); 180 | 181 | mWvCity.addScrollingListener(new OnWheelScrollListener() { 182 | 183 | @Override 184 | public void onScrollingStarted(WheelView wheel) { 185 | } 186 | 187 | @Override 188 | public void onScrollingFinished(WheelView wheel) { 189 | String currentText = (String) cityAdapter.getItemText(wheel.getCurrentItem()); 190 | setTextviewSize(currentText, cityAdapter); 191 | } 192 | }); 193 | 194 | } 195 | 196 | @Override 197 | protected int onGetDialogViewId() { 198 | return R.layout.dialog_province; 199 | } 200 | 201 | private class AddressTextAdapter extends AbstractWheelTextAdapter { 202 | List list; 203 | 204 | protected AddressTextAdapter(Context context, List list, int currentItem, int maxsize, int minsize) { 205 | super(context, R.layout.item_view, NO_RESOURCE, currentItem, maxsize, minsize, selColor, unSelColor); 206 | this.list = list; 207 | setItemTextResource(R.id.tempValue); 208 | } 209 | 210 | @Override 211 | public View getItem(int index, View cachedView, ViewGroup parent) { 212 | View view = super.getItem(index, cachedView, parent); 213 | return view; 214 | } 215 | 216 | @Override 217 | public int getItemsCount() { 218 | return list.size(); 219 | } 220 | 221 | @Override 222 | protected CharSequence getItemText(int index) { 223 | return list.get(index) + ""; 224 | } 225 | } 226 | 227 | /** 228 | * 设置字体大小 229 | * 230 | * @param curriteItemText 231 | * @param adapter 232 | */ 233 | public void setTextviewSize(String curriteItemText, AddressTextAdapter adapter) { 234 | ArrayList arrayList = adapter.getTestViews(); 235 | int size = arrayList.size(); 236 | String currentText; 237 | for (int i = 0; i < size; i++) { 238 | TextView textvew = (TextView) arrayList.get(i); 239 | currentText = textvew.getText().toString(); 240 | if (curriteItemText.equals(currentText)) { 241 | textvew.setTextSize(24); 242 | textvew.setTextColor(selColor); 243 | } else { 244 | textvew.setTextSize(14); 245 | textvew.setTextColor(unSelColor); 246 | } 247 | } 248 | } 249 | 250 | /** 251 | * 根据省找到市 252 | * 253 | * @param provinces 254 | */ 255 | private void initCitys(String province) { 256 | arrCitys.clear(); 257 | for (ProvinceCity provinceCity : provinceCityLists) { 258 | if (provinceCity.getProvince().equals(province)) { 259 | List citys = provinceCity.getCitys(); 260 | if (citys != null && !citys.isEmpty()) { 261 | for (String string : citys) { 262 | arrCitys.add(string); 263 | } 264 | } 265 | } 266 | } 267 | } 268 | 269 | /** 270 | * 初始化地点 271 | * 272 | * @param province 273 | * @param city 274 | */ 275 | public void setAddress(String province, String city) { 276 | if (!TextUtils.isEmpty(province)) { 277 | this.strProvince = province; 278 | } 279 | if (!TextUtils.isEmpty(city)) { 280 | this.strCity = city; 281 | } 282 | } 283 | 284 | /** 285 | * 返回省会索引 286 | * 287 | * @param province 288 | * @return 289 | */ 290 | public int getProvinceItem(String province) { 291 | int size = arrProvinces.size(); 292 | int provinceIndex = 0; 293 | for (int i = 0; i < size; i++) { 294 | if (province.equals(arrProvinces.get(i))) { 295 | return provinceIndex; 296 | } else { 297 | provinceIndex++; 298 | } 299 | } 300 | return provinceIndex; 301 | } 302 | 303 | /** 304 | * 得到城市索引 305 | * 306 | * @param city 307 | * @return 308 | */ 309 | public int getCityItem(String city) { 310 | int size = arrCitys.size(); 311 | int cityIndex = 0; 312 | for (int i = 0; i < size; i++) { 313 | if (city.equals(arrCitys.get(i))) { 314 | return cityIndex; 315 | } else { 316 | cityIndex++; 317 | } 318 | } 319 | return cityIndex; 320 | } 321 | 322 | private String readString(InputStream in) { 323 | try { 324 | BufferedReader br = new BufferedReader(new InputStreamReader(in)); 325 | StringWriter sw = new StringWriter(); 326 | String line; 327 | while ((line = br.readLine()) != null) { 328 | sw.write(line); 329 | } 330 | br.close(); 331 | sw.close(); 332 | return sw.toString(); 333 | } catch (IOException e) { 334 | e.printStackTrace(); 335 | } finally { 336 | 337 | } 338 | return null; 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /app/src/main/java/com/youmu/wheelpicker/model/ProvinceCity.java: -------------------------------------------------------------------------------- 1 | package com.youmu.wheelpicker.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * Created by youzehong on 15/12/27. 10 | */ 11 | public class ProvinceCity implements Parcelable { 12 | 13 | private String province; 14 | private List citys; 15 | 16 | public void setProvince(String province) { 17 | this.province = province; 18 | } 19 | 20 | public void setCitys(List citys) { 21 | this.citys = citys; 22 | } 23 | 24 | public String getProvince() { 25 | return province; 26 | } 27 | 28 | public List getCitys() { 29 | return citys; 30 | } 31 | 32 | @Override 33 | public int describeContents() { 34 | return 0; 35 | } 36 | 37 | @Override 38 | public void writeToParcel(Parcel dest, int flags) { 39 | dest.writeString(this.province); 40 | dest.writeStringList(this.citys); 41 | } 42 | 43 | public ProvinceCity() { 44 | } 45 | 46 | protected ProvinceCity(Parcel in) { 47 | this.province = in.readString(); 48 | this.citys = in.createStringArrayList(); 49 | } 50 | 51 | public static final Creator CREATOR = new Creator() { 52 | public ProvinceCity createFromParcel(Parcel source) { 53 | return new ProvinceCity(source); 54 | } 55 | 56 | public ProvinceCity[] newArray(int size) { 57 | return new ProvinceCity[size]; 58 | } 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/province_wheel_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/province_wheel_val.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 21 | 22 |