Skip to content

Commit

Permalink
- 基于最新版本的 Android Studio Arctic Fox 构建,Gradle 升级到最新的 7.x 版本;
Browse files Browse the repository at this point in the history
- 文本国际化,支持定制多语言(默认为中文及英文);
- 手机号码前缀选择器数据完善,支持全球的国家及地区;
  • Loading branch information
liyujiang-gzu committed Oct 27, 2021
1 parent d72ceda commit dc02097
Show file tree
Hide file tree
Showing 41 changed files with 625 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/
@SuppressWarnings("UnusedReturnValue")
public class CalendarAdapter extends RecyclerView.Adapter<CalendarAdapter.VH> implements OnDateClickListener {
public static String DATE_FORMAT = "yyyy年MM月";
private boolean notify = true;
private ColorScheme colorScheme = new ColorScheme();
private final List<Date> dates = new ArrayList<>();
Expand Down Expand Up @@ -198,7 +199,7 @@ public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
public void onBindViewHolder(@NonNull VH holder, int position) {
holder.titleView.setBackgroundColor(colorScheme.monthTitleBackgroundColor());
holder.titleView.setTextColor(colorScheme.monthTitleTextColor());
holder.titleView.setText(TimeUtils.dateText(getDateValue(position).getTime(), TimeUtils.YY_M_CN));
holder.titleView.setText(TimeUtils.dateText(getDateValue(position).getTime(), DATE_FORMAT));
holder.monthView.setOnDayInMonthClickListener(this);
holder.monthView.setValue(MonthEntity.obtain(valid, select)
.date(dates.get(position))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
* Created by peng on 2017/8/4.
*/
public class MonthEntity implements Serializable {
public static final int WEEK_DAYS = 7;
public static final int MAX_HORIZONTAL_LINES = 6;
public static final int MAX_DAYS_OF_MONTH = 31;
public static final String STR_TODAY = "今天";
public static int WEEK_DAYS = 7;
public static int MAX_HORIZONTAL_LINES = 6;
public static int MAX_DAYS_OF_MONTH = 31;
public static String STR_TODAY = "今天";
private final static List<MonthEntity> pools = new ArrayList<>();
private Date date;
private Interval<Date> valid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
* 时间工具
*/
public class TimeUtils {
public final static String YY_M_CN = "yyyy年MM月";
public final static String YY_MD = "yyyy-MM-dd";

private final static Map<String, SimpleDateFormat> dateMap = new HashMap<>();

private static void ensureDateFormatMap(@NonNull String format) {
Expand All @@ -45,7 +42,9 @@ public static Date date(String dateText, @NonNull String format) throws Exceptio
ensureDateFormatMap(format);
if (dateMap.containsKey(format)) {
SimpleDateFormat sdf = dateMap.get(format);
return sdf.parse(dateText);
if (sdf != null) {
return sdf.parse(dateText);
}
}
return null;
}
Expand All @@ -55,7 +54,9 @@ public static String dateText(long date, @NonNull String format) {
ensureDateFormatMap(format);
if (dateMap.containsKey(format)) {
SimpleDateFormat sdf = dateMap.get(format);
value = sdf.format(new Date(date));
if (sdf != null) {
value = sdf.format(new Date(date));
}
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @since 2021/9/17 14:36
*/
public class WeekAdapter extends BaseAdapter {
private static final String[] DATA = new String[]{
public static String[] DATA = new String[]{
"日", "一", "二", "三", "四", "五", "六"
};
private ColorScheme colorScheme = new ColorScheme();
Expand Down
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 4.0.1 - 2021.10.28

- 基于最新版本的 Android Studio Arctic Fox 构建,Gradle 升级到最新的 7.x 版本;
- 文本国际化,支持定制多语言(默认为中文及英文);
- 手机号码前缀选择器数据完善,支持全球的国家及地区;

## 4.0.0 - 2021.09.18

- 支持设置弹窗样式,内置四种弹窗模式,支持全局弹窗配色,效果请运行Demo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.StyleRes;
import androidx.core.graphics.ColorUtils;

Expand Down Expand Up @@ -239,6 +240,24 @@ public void onClick(View v) {

protected abstract void onOk();

@Override
public void setTitle(@Nullable CharSequence title) {
if (titleView == null) {
return;
}
titleView.post(new Runnable() {
@Override
public void run() {
titleView.setText(title);
}
});
}

@Override
public void setTitle(@StringRes int titleId) {
setTitle(activity.getString(titleId));
}

public final void setBodyWidth(@Dimension(unit = Dimension.DP) @IntRange(from = 50) int bodyWidth) {
ViewGroup.LayoutParams layoutParams = bodyView.getLayoutParams();
int width = WRAP_CONTENT;
Expand Down
4 changes: 2 additions & 2 deletions Common/src/main/res/layout/dialog_footer_style_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:singleLine="true"
android:text="@android:string/cancel"
android:text="@string/dialog_modal_cancel"
android:textColor="#FF333333"
android:textSize="15sp" />

Expand All @@ -46,7 +46,7 @@
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:singleLine="true"
android:text="@android:string/ok"
android:text="@string/dialog_modal_ok"
android:textColor="#FF333333"
android:textSize="15sp" />

Expand Down
2 changes: 1 addition & 1 deletion Common/src/main/res/layout/dialog_footer_style_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:singleLine="true"
android:text="@android:string/ok"
android:text="@string/dialog_modal_ok"
android:textColor="#FF333333"
android:textSize="15sp" />

Expand Down
4 changes: 2 additions & 2 deletions Common/src/main/res/layout/dialog_footer_style_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:text="@android:string/cancel"
android:text="@string/dialog_modal_cancel"
android:textColor="#FF333333"
android:textSize="14sp" />

Expand All @@ -37,7 +37,7 @@
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:text="@android:string/ok"
android:text="@string/dialog_modal_ok"
android:textColor="#FF333333"
android:textSize="14sp" />

Expand Down
2 changes: 1 addition & 1 deletion Common/src/main/res/layout/dialog_header_style_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:paddingEnd="25dp"
android:paddingBottom="15dp"
android:singleLine="true"
android:text="温馨提示"
android:text="@string/dialog_modal_title"
android:textColor="#FF666666"
android:textSize="15sp"
android:textStyle="bold" />
2 changes: 1 addition & 1 deletion Common/src/main/res/layout/dialog_header_style_2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:singleLine="true"
android:text="温馨提示"
android:text="@string/dialog_modal_title"
android:textColor="#FF666666"
android:textSize="15sp"
android:textStyle="bold" />
Expand Down
2 changes: 1 addition & 1 deletion Common/src/main/res/layout/dialog_header_style_3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
android:paddingEnd="25dp"
android:paddingBottom="15dp"
android:singleLine="true"
android:text="温馨提示"
android:text="@string/dialog_modal_title"
android:textColor="#FF666666"
android:textSize="15sp"
android:textStyle="bold" />
4 changes: 2 additions & 2 deletions Common/src/main/res/layout/dialog_header_style_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
android:paddingTop="15dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:text="@android:string/cancel"
android:text="@string/dialog_modal_cancel"
android:textColor="#FF333333"
android:textSize="15sp" />

Expand Down Expand Up @@ -54,7 +54,7 @@
android:paddingTop="15dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:text="@android:string/ok"
android:text="@string/dialog_modal_ok"
android:textColor="#FF0081FF"
android:textSize="15sp" />

Expand Down
20 changes: 20 additions & 0 deletions Common/src/main/res/values-en/dialog_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]>
~
~ The software is licensed under the Mulan PSL v2.
~ You can use this software according to the terms and conditions of the Mulan PSL v2.
~ You may obtain a copy of Mulan PSL v2 at:
~ http://license.coscl.org.cn/MulanPSL2
~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
~ PURPOSE.
~ See the Mulan PSL v2 for more details.
-->

<resources>

<string name="dialog_modal_title">Tips</string>
<string name="dialog_modal_ok">OK</string>
<string name="dialog_modal_cancel">Cancel</string>

</resources>
20 changes: 20 additions & 0 deletions Common/src/main/res/values/dialog_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ Copyright (c) 2016-present 贵州纳雍穿青人李裕江<[email protected]>
~
~ The software is licensed under the Mulan PSL v2.
~ You can use this software according to the terms and conditions of the Mulan PSL v2.
~ You may obtain a copy of Mulan PSL v2 at:
~ http://license.coscl.org.cn/MulanPSL2
~ THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
~ PURPOSE.
~ See the Mulan PSL v2 for more details.
-->

<resources>

<string name="dialog_modal_title">温馨提示</string>
<string name="dialog_modal_ok">确定</string>
<string name="dialog_modal_cancel">取消</string>

</resources>
61 changes: 44 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,12 @@ dependencies {

## 用法示例

常见用法请参阅 [demo](/app),高级用法请细读[源码](/WheelPicker)
诸如可以重写同名的`assets/china_address.json`来自定义省市区数据, 重写同名的`DialogSheetAnimation`来自定义弹窗动画……。 代码是最好的老师,强烈建议拉取代码运行,尝试修改 demo 对比查看实际效果以便加深理解。
常见用法请参阅 [demo](/app),高级用法请细读[源码](/WheelPicker) 诸如可以重写同名的`assets/china_address.json`来自定义省市区数据,
重写同名的`DialogSheetAnimation`来自定义弹窗动画……。 代码是最好的老师,强烈建议拉取代码运行,尝试修改 demo 对比查看实际效果以便加深理解。

### 在 Java 中

```groovy
DialogConfig.setDialogStyle(DialogStyle.One);
...
List<GoodsCategoryBean> data = new ArrayList<>();
data.add(new GoodsCategoryBean(1, "食品生鲜"));
data.add(new GoodsCategoryBean(2, "家用电器"));
Expand All @@ -157,31 +155,27 @@ picker.show();
```

```groovy
DialogConfig.setDialogStyle(DialogStyle.Default);
...
DatePicker picker = new DatePicker(this);
picker.setBodyWidth(240);
//picker.setBodyWidth(240);
DateWheelLayout wheelLayout = picker.getWheelLayout();
wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY);
wheelLayout.setDateLabel("年", "月", "日");
wheelLayout.setRange(DateEntity.today(), DateEntity.yearOnFuture(30), DateEntity.yearOnFuture(10));
//wheelLayout.setDateLabel("年", "月", "日");
wheelLayout.setDateFormatter(new UnitDateFormatter());
wheelLayout.setRange(DateEntity.target(2021, 1, 1), DateEntity.target(2050, 12, 31), DateEntity.today());
wheelLayout.setCurtainEnabled(true);
wheelLayout.setCurtainColor(0xFFCC0000);
wheelLayout.setIndicatorEnabled(true);
wheelLayout.setIndicatorColor(0xFFFF0000);
wheelLayout.setIndicatorSize(view.getResources().getDisplayMetrics().density * 2);
wheelLayout.setTextColor(0xCCCC0000);
wheelLayout.setSelectedTextColor(0xFFFF0000);
wheelLayout.getYearLabelView().setTextColor(0xFF999999);
wheelLayout.getMonthLabelView().setTextColor(0xFF999999);
wheelLayout.getDayLabelView().setTextColor(0xFF999999);
picker.setOnDatePickedListener(this);
//wheelLayout.getYearLabelView().setTextColor(0xFF999999);
//wheelLayout.getMonthLabelView().setTextColor(0xFF999999);
//picker.setOnDatePickedListener(this);
picker.show();
```

```groovy
DialogConfig.setDialogStyle(DialogStyle.Three);
...
AddressPicker picker = new AddressPicker(this);
picker.setAddressMode("city.json", AddressMode.PROVINCE_CITY_COUNTY,
new AddressJsonParser.Builder()
Expand All @@ -199,9 +193,10 @@ picker.setOnAddressPickedListener(this);
picker.show();
```

### 在 XML 中
### 在 XML 中 (可选)

```xml

<com.github.gzuliyujiang.wheelview.widget.WheelView android:id="@+id/wheel_view"
android:layout_width="117dp" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" app:wheel_atmosphericEnabled="true"
Expand All @@ -212,6 +207,7 @@ picker.show();
```

```xml

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical">

Expand All @@ -228,7 +224,7 @@ picker.show();
</LinearLayout>
```

### 定制样式
### 定制样式(可选)

#### 全局配置所有选择器样式及配色

Expand Down Expand Up @@ -325,6 +321,37 @@ public class AntFortuneLikePicker extends LinkagePicker {
}
````

### 国际化多语言(可选)

APP项目中重写以下字符串资源即可,具体名称可查看源代码:

#### dialog_strings.xml

```xml
<resources>
<string name="dialog_modal_title">温馨提示</string>
<string name="dialog_modal_ok">确定</string>
<string name="dialog_modal_cancel">取消</string>
</resources>
```
#### wheel_strings.xml

```xml
<resources>
<string name="wheel_linkage_title">&#160;</string>
<string name="wheel_date_title">日期选择</string>
<string name="wheel_datime_title">日期时间选择</string>
<string name="wheel_time_title">时间选择</string>
<string name="wheel_birthday_title">生日选择</string>
<string name="wheel_car_plate_title">车牌选择</string>
<string name="wheel_option_title">&#160;</string>
<string name="wheel_phone_code_title">手机号码前缀</string>
<string name="wheel_ethnic_title">民族选择</string>
<string name="wheel_number_title">&#160;</string>
<string name="wheel_constellation_title">星座选择</string>
</resources>
```

## 效果预览

以下图片显示的效果可能已修改过,实际效果请运行 demo 查看。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.github.gzuliyujiang.wheelpicker;

import android.app.Activity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
Expand Down Expand Up @@ -43,10 +44,15 @@ public BirthdayPicker(@NonNull Activity activity, @StyleRes int themeResId) {
super(activity, themeResId);
}

@Override
protected void initView(@NonNull View contentView) {
super.initView(contentView);
titleView.setText(R.string.wheel_birthday_title);
}

@Override
protected void initData() {
super.initData();
titleView.setText("生日选择");
Calendar calendar = Calendar.getInstance();
int currentYear = calendar.get(Calendar.YEAR);
int currentMonth = calendar.get(Calendar.MONTH) + 1;
Expand Down
Loading

0 comments on commit dc02097

Please sign in to comment.