Skip to content

Commit

Permalink
- 支持滚轮选择器选中项设置圆角纯色背景;
Browse files Browse the repository at this point in the history
- 所以选择器文本国际化,内置支持中文及英文;
- 手机号码前缀选择器数据完善,支持全球的国家及地区;
- 车牌、星座及性别等选择器调整,民族、星座及性别等默认值设置优化;
- 日历选择器支持自定义节日文本;
  • Loading branch information
liyujiang-gzu committed Oct 28, 2021
1 parent e3d9d73 commit 6fecb7a
Show file tree
Hide file tree
Showing 39 changed files with 1,754 additions and 248 deletions.
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.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
Expand All @@ -33,6 +34,7 @@
import com.github.gzuliyujiang.wheelpicker.impl.AddressProvider;
import com.github.gzuliyujiang.wheelpicker.impl.AssetAddressLoader;
import com.github.gzuliyujiang.wheelpicker.utility.AddressJsonParser;
import com.github.gzuliyujiang.wheelview.widget.WheelView;

import java.util.List;

Expand Down Expand Up @@ -139,4 +141,28 @@ public void setAddressMode(@NonNull String assetPath, @AddressMode int addressMo
setAddressLoader(new AssetAddressLoader(getContext(), assetPath), jsonParser);
}

public final WheelView getProvinceWheelView() {
return wheelLayout.getFirstWheelView();
}

public final WheelView getCityWheelView() {
return wheelLayout.getSecondWheelView();
}

public final WheelView getCountyWheelView() {
return wheelLayout.getThirdWheelView();
}

public final TextView getProvinceLabelView() {
return wheelLayout.getFirstLabelView();
}

public final TextView getCityLabelView() {
return wheelLayout.getSecondLabelView();
}

public final TextView getCountyLabelView() {
return wheelLayout.getThirdLabelView();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.github.gzuliyujiang.calendarpicker.core.CalendarView;
import com.github.gzuliyujiang.calendarpicker.core.ColorScheme;
import com.github.gzuliyujiang.calendarpicker.core.DateUtils;
import com.github.gzuliyujiang.calendarpicker.core.FestivalProvider;
import com.github.gzuliyujiang.calendarpicker.core.OnDateSelectedListener;
import com.github.gzuliyujiang.dialog.DialogConfig;
import com.github.gzuliyujiang.dialog.DialogStyle;
Expand All @@ -45,6 +46,7 @@ public class CalendarPicker extends ModalDialog implements OnDateSelectedListene
private CalendarAdapter calendarAdapter;
private ColorScheme colorScheme;
private boolean singleMode = false;
private FestivalProvider festivalProvider;
private Date minDate, maxDate;
private Date selectDate, startDate, endDate;
private String noteFrom, noteTo;
Expand Down Expand Up @@ -73,12 +75,8 @@ protected void initView() {
setHeight((int) (activity.getResources().getDisplayMetrics().heightPixels * 0.6f));
switch (DialogConfig.getDialogStyle()) {
case DialogStyle.Default:
headerView.setVisibility(View.VISIBLE);
titleView.setText("");
break;
case DialogStyle.Two:
headerView.setVisibility(View.VISIBLE);
titleView.setText("请选择");
break;
default:
headerView.setVisibility(View.GONE);
Expand Down Expand Up @@ -252,10 +250,21 @@ public void setIntervalNotes(String noteFrom, String noteTo) {
}
}

/**
* 设置是否展示节日文本
*/
public void setFestivalProvider(FestivalProvider festivalProvider) {
this.festivalProvider = festivalProvider;
if (initialized) {
refreshData();
}
}

private void refreshData() {
calendarView.setColorScheme(colorScheme);
calendarAdapter.notify(false);
calendarAdapter.single(singleMode);
calendarAdapter.festivalProvider(festivalProvider);
if (singleMode) {
startDate = selectDate;
endDate = selectDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
* Created by peng on 2017/8/3.
Expand All @@ -42,9 +43,16 @@ public class CalendarAdapter extends RecyclerView.Adapter<CalendarAdapter.VH> im
private final Interval<Date> select = new Interval<>();
private final Interval<String> selectNote = new Interval<>();
private boolean singleMode = false;
private FestivalProvider festivalProvider;
private Date lastClickDate = null;
private OnDateSelectedListener onDateSelectedListener;

static {
if (!Locale.getDefault().getDisplayLanguage().contains("中文")) {
DATE_FORMAT = "MMM, yyyy";
}
}

public CalendarAdapter notify(boolean notify) {
this.notify = notify;
return this;
Expand All @@ -66,6 +74,14 @@ public CalendarAdapter single(boolean value) {
return this;
}

public CalendarAdapter festivalProvider(FestivalProvider value) {
festivalProvider = value;
if (notify) {
refresh();
}
return this;
}

public CalendarAdapter valid(Date from, Date to) {
valid.left(from);
valid.right(to);
Expand Down Expand Up @@ -204,6 +220,7 @@ public void onBindViewHolder(@NonNull VH holder, int position) {
holder.monthView.setValue(MonthEntity.obtain(valid, select)
.date(dates.get(position))
.singleMode(singleMode)
.festivalProvider(festivalProvider)
.note(selectNote), colorScheme);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.
*/

package com.github.gzuliyujiang.calendarpicker.core;

import java.util.Date;

/**
* @author 贵州山野羡民([email protected]
* @since 2021/10/28 9:52
*/
public interface FestivalProvider {

String provideText(Date date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
* Created by peng on 2017/8/4.
Expand All @@ -32,6 +33,13 @@ public class MonthEntity implements Serializable {
private Interval<Date> select;
private Interval<String> note;
private boolean singleMode = false;
private FestivalProvider festivalProvider;

static {
if (!Locale.getDefault().getDisplayLanguage().contains("中文")) {
STR_TODAY = "Today";
}
}

public static MonthEntity obtain(Interval<Date> valid, Interval<Date> select) {
MonthEntity entity = pools.size() == 0 ? new MonthEntity() : pools.remove(0);
Expand Down Expand Up @@ -71,15 +79,24 @@ public MonthEntity select(Interval<Date> select) {
return this;
}

public MonthEntity singleMode(boolean single) {
this.singleMode = single;
public MonthEntity singleMode(boolean singleMode) {
this.singleMode = singleMode;
return this;
}

public boolean singleMode() {
return this.singleMode;
}

public MonthEntity festivalProvider(FestivalProvider festivalProvider) {
this.festivalProvider = festivalProvider;
return this;
}

public FestivalProvider festivalProvider() {
return this.festivalProvider;
}

public Interval<String> note() {
return note;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
* 月份控件
Expand Down Expand Up @@ -197,41 +195,17 @@ public void onClick(View v) {
}

@NonNull
private String toDayDesc(int index) {
protected String toDayDesc(int index) {
FestivalProvider festivalProvider = monthEntity.festivalProvider();
if (festivalProvider == null) {
return "";
}
Date date = DateUtils.specialDayInMonth(monthEntity.date(), index);
String monthDay = new SimpleDateFormat("MMdd", Locale.PRC).format(date);
switch (monthDay) {
case "0101":
return "元旦";
case "0214":
return "情人节";
case "0308":
return "妇女节";
case "0312":
return "植树节";
case "0401":
return "愚人节";
case "0501":
return "劳动节";
case "0504":
return "青年节";
case "0601":
return "儿童节";
case "0701":
return "建党节";
case "0801":
return "建军节";
case "0910":
return "教师节";
case "1001":
return "国庆节";
case "1111":
return "光棍节";
case "1225":
return "圣诞节";
default:
return "";
String festival = festivalProvider.provideText(date);
if (festival == null) {
festival = "";
}
return festival;
}

public void setValue(@NonNull MonthEntity entity, @NonNull ColorScheme colorScheme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.Locale;

/**
* @author 贵州山野羡民([email protected]
* @since 2021/9/17 14:36
Expand All @@ -30,6 +32,14 @@ public class WeekAdapter extends BaseAdapter {
};
private ColorScheme colorScheme = new ColorScheme();

static {
if (!Locale.getDefault().getDisplayLanguage().contains("中文")) {
DATA = new String[]{
"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"
};
}
}

public void setColorScheme(ColorScheme colorScheme) {
if (colorScheme == null) {
colorScheme = new ColorScheme();
Expand Down
8 changes: 5 additions & 3 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# 更新日志

## 4.0.2 - 2021.10.28
## 4.1.0 - 2021.10.28

- 基于最新版本的 Android Studio Arctic Fox 构建,Gradle 升级到最新的 7.x 版本
- 文本国际化,支持定制多语言(默认为中文及英文)
- 支持滚轮选择器选中项设置圆角纯色背景
- 所以选择器文本国际化,内置支持中文及英文
- 手机号码前缀选择器数据完善,支持全球的国家及地区;
- 车牌、星座及性别等选择器调整,民族、星座及性别等默认值设置优化;
- 日历选择器支持自定义节日文本;

## 4.0.1 - 2021.09.26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ protected View createBodyView() {
protected void initView() {
super.initView();
setHeight((int) (activity.getResources().getDisplayMetrics().heightPixels * 0.6f));
titleView.setText(explorerMode == ExplorerMode.FILE ? "文件选择" : "目录选择");
if (explorerMode == ExplorerMode.FILE) {
okView.setVisibility(View.GONE);
}
Expand Down
2 changes: 1 addition & 1 deletion FilePicker/src/main/res/layout/file_picker_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="&lt;Empty&gt;"
android:textColor="#FF999999"
android:visibility="invisible"
tools:text="&lt;Empty&gt;"
tools:visibility="visible" />

</FrameLayout>
Expand Down
Loading

0 comments on commit 6fecb7a

Please sign in to comment.