Skip to content

Commit ee3d6dd

Browse files
committed
- 联动选择器增加初始数据加载进度控制,地址选择器数据加载过程避免卡顿感; - 以日期选择器为例示范选择器界面个性化用法,参阅 [issues#243](https://github.com/gzu-liyujiang/AndroidPicker/issues/243);
1 parent 139f3d9 commit ee3d6dd

10 files changed

Lines changed: 194 additions & 66 deletions

File tree

AddressPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/AddressPicker.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.github.gzuliyujiang.wheelpicker.contract.AddressParser;
2424
import com.github.gzuliyujiang.wheelpicker.contract.AddressReceiver;
2525
import com.github.gzuliyujiang.wheelpicker.contract.LinkageProvider;
26+
import com.github.gzuliyujiang.wheelpicker.contract.OnAddressLoadListener;
2627
import com.github.gzuliyujiang.wheelpicker.contract.OnAddressPickedListener;
2728
import com.github.gzuliyujiang.wheelpicker.contract.OnLinkagePickedListener;
2829
import com.github.gzuliyujiang.wheelpicker.entity.CityEntity;
@@ -53,6 +54,7 @@ public class AddressPicker extends LinkagePicker implements AddressReceiver {
5354
private AddressParser addressParser;
5455
private int addressMode;
5556
private OnAddressPickedListener onAddressPickedListener;
57+
private OnAddressLoadListener onAddressLoadListener;
5658

5759
public AddressPicker(@NonNull Activity activity) {
5860
super(activity);
@@ -68,11 +70,19 @@ protected void initData() {
6870
if (addressLoader == null || addressParser == null) {
6971
return;
7072
}
73+
wheelLayout.showLoading();
74+
if (onAddressLoadListener != null) {
75+
onAddressLoadListener.onAddressLoadStarted();
76+
}
7177
addressLoader.loadJson(this, addressParser);
7278
}
7379

7480
@Override
7581
public void onAddressReceived(@NonNull List<ProvinceEntity> data) {
82+
wheelLayout.hideLoading();
83+
if (onAddressLoadListener != null) {
84+
onAddressLoadListener.onAddressLoadFinished(data);
85+
}
7686
wheelLayout.setData(new AddressProvider(data, addressMode));
7787
}
7888

@@ -103,6 +113,10 @@ public void setOnAddressPickedListener(@NonNull OnAddressPickedListener onAddres
103113
this.onAddressPickedListener = onAddressPickedListener;
104114
}
105115

116+
public void setOnAddressLoadListener(@NonNull OnAddressLoadListener onAddressLoadListener) {
117+
this.onAddressLoadListener = onAddressLoadListener;
118+
}
119+
106120
public void setAddressLoader(@NonNull AddressLoader loader, @NonNull AddressParser parser) {
107121
this.addressLoader = loader;
108122
this.addressParser = parser;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2016-present 贵州纳雍穿青人李裕江<1032694760@qq.com>
3+
*
4+
* The software is licensed under the Mulan PSL v2.
5+
* You can use this software according to the terms and conditions of the Mulan PSL v2.
6+
* You may obtain a copy of Mulan PSL v2 at:
7+
* http://license.coscl.org.cn/MulanPSL2
8+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
9+
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
10+
* PURPOSE.
11+
* See the Mulan PSL v2 for more details.
12+
*/
13+
14+
package com.github.gzuliyujiang.wheelpicker.contract;
15+
16+
import androidx.annotation.NonNull;
17+
18+
import com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity;
19+
20+
import java.util.List;
21+
22+
/**
23+
* @author 贵州山野羡民(1032694760@qq.com)
24+
* @since 2021/6/30 15:20
25+
*/
26+
public interface OnAddressLoadListener {
27+
28+
void onAddressLoadStarted();
29+
30+
void onAddressLoadFinished(@NonNull List<ProvinceEntity> data);
31+
32+
}

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# 更新日志
22

3+
## 3.0.4 - 2021.06.30
4+
5+
- 联动选择器增加初始数据加载进度控制,地址选择器数据加载过程避免卡顿感;
6+
- 以日期选择器为例示范选择器界面个性化用法,参阅 [issues#243](https://github.com/gzu-liyujiang/AndroidPicker/issues/243)
7+
- 地址选择器新增国家统计局省市区数据示例;
8+
39
## 3.0.3 - 2021.06.25
410

511
- 滚轮控件默认值设置优化;

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ dependencies {
134134

135135
## 用法示例
136136

137-
常见用法请参阅 [demo](/app),高级用法请细读[源码](/WheelPicker)。强烈建议拉取代码运行,尝试修改 demo 对比查看实际效果以便加深理解。
137+
常见用法请参阅 [demo](/app),高级用法请细读[源码](/WheelPicker)代码是最好的老师,强烈建议拉取代码运行,尝试修改 demo 对比查看实际效果以便加深理解。
138138

139139
### 在 Java 中
140140

@@ -149,7 +149,28 @@ dependencies {
149149
picker.getWheelView().setCurvedMaxAngle(60);
150150
picker.show();
151151
```
152-
152+
```groovy
153+
DatePicker picker = new DatePicker(this);
154+
picker.setOnDatePickedListener(this);
155+
picker.setBodyWidth(240);
156+
picker.setBackgroundColor(0xEEDDDDDD);
157+
picker.getHeaderView().setBackgroundColor(0xFFCCCCCC);
158+
DateWheelLayout wheelLayout = picker.getWheelLayout();
159+
wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY);
160+
wheelLayout.setDateLabel("年", "月", "日");
161+
wheelLayout.setRange(DateEntity.today(), DateEntity.target(2020, 12, 31), DateEntity.today());
162+
wheelLayout.setCurtainEnabled(true);
163+
wheelLayout.setCurtainColor(0xFFCC0000);
164+
wheelLayout.setIndicatorEnabled(true);
165+
wheelLayout.setIndicatorColor(0xFFFF0000);
166+
wheelLayout.setIndicatorSize(view.getResources().getDisplayMetrics().density * 2);
167+
wheelLayout.setTextColor(0xCCCC0000);
168+
wheelLayout.setSelectedTextColor(0xFF00FF00);
169+
wheelLayout.getYearWheelView().setBackgroundColor(0x90CCCCCC);
170+
wheelLayout.getMonthWheelView().setBackgroundColor(0x90CCCCCC);
171+
wheelLayout.getDayWheelView().setBackgroundColor(0x90CCCCCC);
172+
picker.show();
173+
```
153174
```groovy
154175
AddressPicker picker = new AddressPicker(this);
155176
picker.setAddressMode(AddressMode.PROVINCE_CITY_COUNTY);

WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/LinkagePicker.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import android.app.Activity;
1717
import android.view.View;
18+
import android.widget.ProgressBar;
1819
import android.widget.TextView;
1920

2021
import androidx.annotation.NonNull;
@@ -111,4 +112,8 @@ public final TextView getThirdLabelView() {
111112
return wheelLayout.getThirdLabelView();
112113
}
113114

115+
public final ProgressBar getLoadingView() {
116+
return wheelLayout.getLoadingView();
117+
}
118+
114119
}

WheelPicker/src/main/java/com/github/gzuliyujiang/wheelpicker/widget/LinkageWheelLayout.java

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import android.content.Context;
1717
import android.content.res.TypedArray;
1818
import android.util.AttributeSet;
19+
import android.widget.ProgressBar;
1920
import android.widget.TextView;
2021

2122
import androidx.annotation.NonNull;
@@ -40,6 +41,7 @@
4041
public class LinkageWheelLayout extends BaseWheelLayout {
4142
private WheelView firstWheelView, secondWheelView, thirdWheelView;
4243
private TextView firstLabelView, secondLabelView, thirdLabelView;
44+
private ProgressBar loadingView;
4345
private Object firstValue, secondValue, thirdValue;
4446
private int firstIndex, secondIndex, thirdIndex;
4547
private LinkageProvider dataProvider;
@@ -84,6 +86,7 @@ protected void onInit(@NonNull Context context) {
8486
firstLabelView = findViewById(R.id.wheel_picker_linkage_first_label);
8587
secondLabelView = findViewById(R.id.wheel_picker_linkage_second_label);
8688
thirdLabelView = findViewById(R.id.wheel_picker_linkage_third_label);
89+
loadingView = findViewById(R.id.wheel_picker_linkage_loading);
8790
}
8891

8992
@Override
@@ -171,32 +174,16 @@ public void setLabel(CharSequence first, CharSequence second, CharSequence third
171174
thirdLabelView.setText(third);
172175
}
173176

174-
public void setOnLinkageSelectedListener(OnLinkageSelectedListener onLinkageSelectedListener) {
175-
this.onLinkageSelectedListener = onLinkageSelectedListener;
177+
public void showLoading() {
178+
loadingView.setVisibility(VISIBLE);
176179
}
177180

178-
public final WheelView getFirstWheelView() {
179-
return firstWheelView;
181+
public void hideLoading() {
182+
loadingView.setVisibility(GONE);
180183
}
181184

182-
public final WheelView getSecondWheelView() {
183-
return secondWheelView;
184-
}
185-
186-
public final WheelView getThirdWheelView() {
187-
return thirdWheelView;
188-
}
189-
190-
public final TextView getFirstLabelView() {
191-
return firstLabelView;
192-
}
193-
194-
public final TextView getSecondLabelView() {
195-
return secondLabelView;
196-
}
197-
198-
public final TextView getThirdLabelView() {
199-
return thirdLabelView;
185+
public void setOnLinkageSelectedListener(OnLinkageSelectedListener onLinkageSelectedListener) {
186+
this.onLinkageSelectedListener = onLinkageSelectedListener;
200187
}
201188

202189
public void setFirstVisible(boolean visible) {
@@ -252,4 +239,32 @@ private void changeThirdData() {
252239
thirdWheelView.setDefaultPosition(thirdIndex);
253240
}
254241

242+
public final WheelView getFirstWheelView() {
243+
return firstWheelView;
244+
}
245+
246+
public final WheelView getSecondWheelView() {
247+
return secondWheelView;
248+
}
249+
250+
public final WheelView getThirdWheelView() {
251+
return thirdWheelView;
252+
}
253+
254+
public final TextView getFirstLabelView() {
255+
return firstLabelView;
256+
}
257+
258+
public final TextView getSecondLabelView() {
259+
return secondLabelView;
260+
}
261+
262+
public final TextView getThirdLabelView() {
263+
return thirdLabelView;
264+
}
265+
266+
public final ProgressBar getLoadingView() {
267+
return loadingView;
268+
}
269+
255270
}

WheelPicker/src/main/res/layout/wheel_picker_linkage.xml

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,66 @@
1111
~ See the Mulan PSL v2 for more details.
1212
-->
1313

14-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
14+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
1515
android:layout_width="match_parent"
16-
android:layout_height="wrap_content"
17-
android:orientation="horizontal">
16+
android:layout_height="wrap_content">
1817

19-
<com.github.gzuliyujiang.wheelview.widget.WheelView
20-
android:id="@+id/wheel_picker_linkage_first_wheel"
21-
style="@style/WheelDefault"
22-
android:layout_width="0dp"
18+
<LinearLayout
19+
android:layout_width="match_parent"
2320
android:layout_height="wrap_content"
24-
android:layout_weight="1.0" />
21+
android:orientation="horizontal">
2522

26-
<TextView
27-
android:id="@+id/wheel_picker_linkage_first_label"
28-
android:layout_width="wrap_content"
29-
android:layout_height="wrap_content"
30-
android:layout_gravity="center_vertical"
31-
android:text="" />
23+
<com.github.gzuliyujiang.wheelview.widget.WheelView
24+
android:id="@+id/wheel_picker_linkage_first_wheel"
25+
style="@style/WheelDefault"
26+
android:layout_width="0dp"
27+
android:layout_height="wrap_content"
28+
android:layout_weight="1.0" />
3229

33-
<com.github.gzuliyujiang.wheelview.widget.WheelView
34-
android:id="@+id/wheel_picker_linkage_second_wheel"
35-
style="@style/WheelDefault"
36-
android:layout_width="0dp"
37-
android:layout_height="wrap_content"
38-
android:layout_weight="1.0" />
30+
<TextView
31+
android:id="@+id/wheel_picker_linkage_first_label"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:layout_gravity="center_vertical"
35+
android:text="" />
3936

40-
<TextView
41-
android:id="@+id/wheel_picker_linkage_second_label"
42-
android:layout_width="wrap_content"
43-
android:layout_height="wrap_content"
44-
android:layout_gravity="center_vertical"
45-
android:text="" />
37+
<com.github.gzuliyujiang.wheelview.widget.WheelView
38+
android:id="@+id/wheel_picker_linkage_second_wheel"
39+
style="@style/WheelDefault"
40+
android:layout_width="0dp"
41+
android:layout_height="wrap_content"
42+
android:layout_weight="1.0" />
4643

47-
<com.github.gzuliyujiang.wheelview.widget.WheelView
48-
android:id="@+id/wheel_picker_linkage_third_wheel"
49-
style="@style/WheelDefault"
50-
android:layout_width="0dp"
51-
android:layout_height="wrap_content"
52-
android:layout_weight="1.0"
53-
android:visibility="visible" />
44+
<TextView
45+
android:id="@+id/wheel_picker_linkage_second_label"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_gravity="center_vertical"
49+
android:text="" />
50+
51+
<com.github.gzuliyujiang.wheelview.widget.WheelView
52+
android:id="@+id/wheel_picker_linkage_third_wheel"
53+
style="@style/WheelDefault"
54+
android:layout_width="0dp"
55+
android:layout_height="wrap_content"
56+
android:layout_weight="1.0"
57+
android:visibility="visible" />
58+
59+
<TextView
60+
android:id="@+id/wheel_picker_linkage_third_label"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:layout_gravity="center_vertical"
64+
android:text="" />
65+
66+
</LinearLayout>
5467

55-
<TextView
56-
android:id="@+id/wheel_picker_linkage_third_label"
68+
<ProgressBar
69+
android:id="@+id/wheel_picker_linkage_loading"
70+
style="@android:style/Widget.ProgressBar"
5771
android:layout_width="wrap_content"
5872
android:layout_height="wrap_content"
59-
android:layout_gravity="center_vertical"
60-
android:text="" />
73+
android:layout_gravity="center"
74+
android:visibility="invisible" />
6175

62-
</LinearLayout>
76+
</FrameLayout>

app/src/main/java/com/github/gzuliyujiang/fallback/activity/DateTimePickerActivity.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.github.gzuliyujiang.wheelpicker.entity.TimeEntity;
3636
import com.github.gzuliyujiang.wheelpicker.impl.UnitDateFormatter;
3737
import com.github.gzuliyujiang.wheelpicker.impl.UnitTimeFormatter;
38+
import com.github.gzuliyujiang.wheelpicker.widget.DateWheelLayout;
3839

3940
/**
4041
* 日期时间滚轮选择器
@@ -79,12 +80,25 @@ public void onYearMonthDayTime(View view) {
7980
}
8081

8182
public void onYearMonthDay(View view) {
82-
DateEntity today = DateEntity.today();
8383
DatePicker picker = new DatePicker(this);
8484
picker.setOnDatePickedListener(this);
85-
picker.getWheelLayout().setDateMode(DateMode.YEAR_MONTH_DAY);
86-
picker.getWheelLayout().setDateLabel("年", "月", "日");
87-
picker.getWheelLayout().setRange(today, DateEntity.target(2020, 12, 31), today);
85+
picker.setBodyWidth(240);
86+
picker.setBackgroundColor(0xEEDDDDDD);
87+
picker.getHeaderView().setBackgroundColor(0xFFCCCCCC);
88+
DateWheelLayout wheelLayout = picker.getWheelLayout();
89+
wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY);
90+
wheelLayout.setDateLabel("年", "月", "日");
91+
wheelLayout.setRange(DateEntity.today(), DateEntity.target(2020, 12, 31), DateEntity.today());
92+
wheelLayout.setCurtainEnabled(true);
93+
wheelLayout.setCurtainColor(0xFFCC0000);
94+
wheelLayout.setIndicatorEnabled(true);
95+
wheelLayout.setIndicatorColor(0xFFFF0000);
96+
wheelLayout.setIndicatorSize(view.getResources().getDisplayMetrics().density * 2);
97+
wheelLayout.setTextColor(0xCCCC0000);
98+
wheelLayout.setSelectedTextColor(0xFF00FF00);
99+
wheelLayout.getYearWheelView().setBackgroundColor(0x90CCCCCC);
100+
wheelLayout.getMonthWheelView().setBackgroundColor(0x90CCCCCC);
101+
wheelLayout.getDayWheelView().setBackgroundColor(0x90CCCCCC);
88102
picker.show();
89103
}
90104

0 commit comments

Comments
 (0)