Skip to content

Commit

Permalink
- 支持设置弹窗样式,内置四种弹窗模式,效果请运行Demo; - 日历日期选择器默认选中项展示到当前可见位置,Demo日历日期选择器自定义…
Browse files Browse the repository at this point in the history
…配色示例; - 滚轮选择器滚动变化监听器优化,Demo滚轮选择器实时滚动变化监听示例; - 文件目录选择器界面调整; - 颜色选择器界面调整; - 其他已知的小缺陷修复及代码优化;
  • Loading branch information
liyujiang-gzu committed Sep 16, 2021
1 parent 9ed05cb commit 8abb24d
Show file tree
Hide file tree
Showing 81 changed files with 1,341 additions and 802 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public AddressPicker(@NonNull Activity activity, @StyleRes int themeResId) {
@Override
protected void initData() {
super.initData();
titleView.setText("地址选择");
if (addressLoader == null || addressParser == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import androidx.annotation.NonNull;

import com.github.gzuliyujiang.basepicker.PickerLog;
import com.github.gzuliyujiang.dialog.DialogLog;
import com.github.gzuliyujiang.wheelpicker.contract.AddressParser;
import com.github.gzuliyujiang.wheelpicker.entity.CityEntity;
import com.github.gzuliyujiang.wheelpicker.entity.CountyEntity;
Expand Down Expand Up @@ -54,7 +54,7 @@ public List<ProvinceEntity> parseData(@NonNull String text) {
JSONArray provinceArray = new JSONArray(text);
return parseProvince(provinceArray);
} catch (JSONException e) {
PickerLog.print(e);
DialogLog.print(e);
}
return new ArrayList<>();
}
Expand Down
1 change: 0 additions & 1 deletion CalendarPicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

```groovy
CalendarPicker picker = new CalendarPicker(this);
picker.enableRoundCorner();
picker.setRangeDateOnFuture(3);
if (singleTimeInMillis == 0) {
singleTimeInMillis = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;

import com.github.gzuliyujiang.basepicker.ConfirmPicker;
import com.github.gzuliyujiang.calendarpicker.calendar.adapter.CalendarAdapter;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectListener;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectedListener;
import com.github.gzuliyujiang.calendarpicker.calendar.utils.DateUtils;
import com.github.gzuliyujiang.calendarpicker.calendar.view.CalendarView;
import com.github.gzuliyujiang.dialog.DialogConfig;
import com.github.gzuliyujiang.dialog.DialogStyle;
import com.github.gzuliyujiang.dialog.ModalDialog;

import java.util.Calendar;
import java.util.Date;
Expand All @@ -39,9 +39,8 @@
* @since 2019/4/30 13:36
*/
@SuppressWarnings({"unused", "deprecation"})
public class CalendarPicker extends ConfirmPicker implements OnCalendarSelectedListener, OnCalendarSelectListener {
public class CalendarPicker extends ModalDialog implements OnCalendarSelectedListener {
private CalendarView calendarView;
private FrameLayout bottomView;
private CalendarAdapter calendarAdapter;
private boolean singleMode = false;
private Date minDate, maxDate;
Expand All @@ -61,18 +60,27 @@ public CalendarPicker(@NonNull Activity activity, @StyleRes int themeResId) {

@NonNull
@Override
protected View createBodyView(@NonNull Activity activity) {
View view = View.inflate(activity, R.layout.calendar_picker, null);
calendarView = view.findViewById(R.id.calendar_picker_body);
bottomView = view.findViewById(R.id.calendar_picker_bottom);
return view;
protected View createBodyView() {
return View.inflate(activity, R.layout.calendar_picker, null);
}

@Override
protected void initView(@NonNull View contentView) {
super.initView(contentView);
if (DialogConfig.getDialogStyle() == DialogStyle.Two) {
headerView.setVisibility(View.VISIBLE);
titleView.setText("日期选择");
} else {
headerView.setVisibility(View.GONE);
}
calendarView = contentView.findViewById(R.id.calendar_picker_body);
}

@Override
protected void initData() {
super.initData();
initialized = true;
setHeight((int) (calendarView.getResources().getDisplayMetrics().heightPixels * 0.6));
setHeight((int) (activity.getResources().getDisplayMetrics().heightPixels * 0.6f));
calendarAdapter = calendarView.getAdapter();
calendarAdapter.setOnCalendarSelectedListener(this);
refreshData();
Expand Down Expand Up @@ -112,17 +120,6 @@ public void onRangeSelected(@NonNull Date start, @NonNull Date end) {
endDate = end;
}

@Override
public void onSingleSelect(@NonNull Date date) {
selectDate = date;
}

@Override
public void onDoubleSelect(@NonNull Date before, @NonNull Date after) {
startDate = before;
endDate = after;
}

/**
* 设置日期范围选择回调
*/
Expand Down Expand Up @@ -242,16 +239,10 @@ private void scrollToSelectedPosition() {
calendarView.post(new Runnable() {
@Override
public void run() {
final Calendar selectedCalendar = DateUtils.calendar(startDate.getTime() + (endDate.getTime() - startDate.getTime()) / 2);
int position = calendarAdapter.getDatePosition(selectedCalendar.getTime());
int position = calendarAdapter.getDatePosition(startDate);
position = Math.max(position, 0);
position = Math.min(position, calendarAdapter.getItemCount() - 1);
if (position == 0) {
calendarView.getBodyView().scrollToPosition(0);
return;
}
int offset = (int) (-60 * calendarView.getResources().getDisplayMetrics().density);
calendarView.getLayoutManager().scrollToPositionWithOffset(position, offset);
calendarView.getLayoutManager().scrollToPositionWithOffset(position, 0);
}
});
}
Expand All @@ -260,8 +251,4 @@ public final CalendarView getCalendarView() {
return calendarView;
}

public final FrameLayout getBottomView() {
return bottomView;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import com.github.gzuliyujiang.calendarpicker.calendar.protocol.Interval;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.MonthEntity;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectListener;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarDayClickListener;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarSelectedListener;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnMonthClickListener;
import com.github.gzuliyujiang.calendarpicker.calendar.utils.DateUtils;
import com.github.gzuliyujiang.calendarpicker.calendar.view.MonthView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

Expand All @@ -36,16 +36,14 @@
* Created by peng on 2017/8/3.
*/
@SuppressWarnings("UnusedReturnValue")
public class CalendarAdapter extends RecyclerView.Adapter<CalendarViewHolder> implements OnMonthClickListener {
public class CalendarAdapter extends RecyclerView.Adapter<CalendarViewHolder> implements OnCalendarDayClickListener {
private boolean notify = true;
private final List<Date> dates = new ArrayList<>();
private final Interval<Date> valid = new Interval<>();
private final Interval<Date> select = new Interval<>();
private final Interval<String> selectNote = new Interval<>();
private boolean singleMode = false;
private Date lastClickDate = null;
@SuppressWarnings("deprecation")
private OnCalendarSelectListener calendarSelectListener;
private OnCalendarSelectedListener onCalendarSelectedListener;

public CalendarAdapter notify(boolean notify) {
Expand Down Expand Up @@ -121,7 +119,7 @@ public CalendarAdapter range(Date startDate, Date endDate) {
}

public CalendarAdapter range(Date startDate, Date endDate, boolean clear) {
List<Date> dates = DateUtils.fillMonths(startDate, endDate);
List<Date> dates = DateUtils.fillDates(startDate, endDate);
return range(dates, clear);
}

Expand All @@ -143,7 +141,7 @@ public CalendarAdapter range(List<Date> list, boolean clear) {
*/
@Deprecated
public CalendarAdapter setRange(Date startDate, Date endDate, boolean clear, boolean notify) {
List<Date> dates = DateUtils.fillMonths(startDate, endDate);
List<Date> dates = DateUtils.fillDates(startDate, endDate);
this.notify = notify;
return range(dates, clear);
}
Expand All @@ -166,15 +164,6 @@ public void setOnCalendarSelectedListener(OnCalendarSelectedListener onCalendarS
this.onCalendarSelectedListener = onCalendarSelectedListener;
}

/**
* @deprecated 使用 {@link #setOnCalendarSelectedListener(OnCalendarSelectedListener)} 代替
*/
@Deprecated
@SuppressWarnings("deprecation")
public void setOnCalendarSelectListener(OnCalendarSelectListener listener) {
calendarSelectListener = listener;
}

@NonNull
@Override
public CalendarViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Expand Down Expand Up @@ -202,22 +191,34 @@ public int getItemCount() {
}

public final int getDatePosition(Date date) {
int position = -1;
if (dates.size() > 1) {
if (date.getTime() <= dates.get(0).getTime()) {
position = 0;
} else if (date.getTime() >= dates.get(dates.size() - 1).getTime()) {
position = dates.size() - 1;
} else {
for (int i = 0; i < dates.size() - 1; i++) {
if (date.getTime() >= dates.get(i).getTime() && date.getTime() <= dates.get(i + 1).getTime()) {
position = i;
break;
}
}
int size = dates.size();
if (size <= 1) {
return 0;
}
long time = date.getTime();
if (time <= dates.get(0).getTime()) {
return 0;
}
int lastPosition = size - 1;
if (time >= dates.get(lastPosition).getTime()) {
return lastPosition;
}
for (int i = 0; i < lastPosition; i++) {
Calendar minDate = DateUtils.calendar(dates.get(i).getTime());
minDate.set(Calendar.DAY_OF_MONTH, 1);
minDate.set(Calendar.HOUR_OF_DAY, 0);
minDate.set(Calendar.MINUTE, 0);
minDate.set(Calendar.SECOND, 0);
Calendar maxDate = DateUtils.calendar(dates.get(i).getTime());
maxDate.set(Calendar.DAY_OF_MONTH, DateUtils.maxDaysOfMonth(maxDate.getTime()));
maxDate.set(Calendar.HOUR_OF_DAY, 23);
maxDate.set(Calendar.MINUTE, 59);
maxDate.set(Calendar.SECOND, 59);
if (time >= minDate.getTime().getTime() && time <= maxDate.getTime().getTime()) {
return i;
}
}
return position;
return -1;
}

public Date value(int position) {
Expand All @@ -228,16 +229,13 @@ public Date value(int position) {
}

@Override
public void onMonthClick(Date date) {
public void onCalendarDayClick(Date date) {
if (null == date) {
return;
}
if (null == lastClickDate || singleMode) {
lastClickDate = date;
select(date, date).refresh();
if (null != calendarSelectListener) {
calendarSelectListener.onSingleSelect(date);
}
if (null != onCalendarSelectedListener) {
onCalendarSelectedListener.onSingleSelected(date);
}
Expand All @@ -246,17 +244,11 @@ public void onMonthClick(Date date) {
if (lastClickDate.getTime() >= date.getTime()) {
lastClickDate = date;
select(date, date).refresh();
if (null != calendarSelectListener) {
calendarSelectListener.onSingleSelect(date);
}
if (null != onCalendarSelectedListener) {
onCalendarSelectedListener.onSingleSelected(date);
}
} else {
select(lastClickDate, date).refresh();
if (null != calendarSelectListener) {
calendarSelectListener.onDoubleSelect(lastClickDate, date);
}
if (null != onCalendarSelectedListener) {
onCalendarSelectedListener.onRangeSelected(lastClickDate, date);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* 月份中日期点击回调
* Created by peng on 2017/8/4.
*/
public interface OnMonthClickListener {
public interface OnCalendarDayClickListener {

void onMonthClick(Date date);
void onCalendarDayClick(Date date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static Date min(Date sDate, Date eDate) {
* @param eDate 结束日期
* @return 区间内各月的Date
*/
public static List<Date> fillMonths(Date sDate, Date eDate) {
public static List<Date> fillDates(Date sDate, Date eDate) {
List<Date> dates = new ArrayList<>();
if (null == sDate || null == eDate) {
dates.add(new Date());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public String getGroupName(int position) {
.setDivideColor(ContextCompat.getColor(getContext(), R.color.calendar_month_divide_line_color)) //分割线颜色
.setDivideHeight((int) getResources().getDimension(R.dimen.calendar_decoration_divide_line_height))
//分割线高度 (默认没有分割线)
.setGroupTextColor(ContextCompat.getColor(getContext(), R.color.calendar_text_decoration_color))
.setGroupTextColor(ContextCompat.getColor(getContext(), R.color.calendar_decoration_text_color))
//字体颜色
.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)) //加粗
.setGroupTextSize((int) getResources().getDimension(R.dimen.calendar_decoration_text_size)) //字体大小
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.DayEntity;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.MonthEntity;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.NInterval;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnMonthClickListener;
import com.github.gzuliyujiang.calendarpicker.calendar.protocol.OnCalendarDayClickListener;
import com.github.gzuliyujiang.calendarpicker.calendar.utils.DateUtils;

import java.util.Date;
Expand Down Expand Up @@ -213,9 +213,9 @@ public MonthEntity value() {
return monthEntity;
}

private OnMonthClickListener onDayInMonthClickListener;
private OnCalendarDayClickListener onDayInMonthClickListener;

public void setOnDayInMonthClickListener(OnMonthClickListener listener) {
public void setOnDayInMonthClickListener(OnCalendarDayClickListener listener) {
onDayInMonthClickListener = listener;
}

Expand All @@ -233,7 +233,7 @@ public void onClick(View v) {
DayEntity entity = dayView.value();
Date month = new Date(monthEntity.date().getTime());
Date dayDate = DateUtils.specialDayInMonth(month, entity.intValue());
onDayInMonthClickListener.onMonthClick(dayDate);
onDayInMonthClickListener.onCalendarDayClick(dayDate);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
5 changes: 3 additions & 2 deletions CalendarPicker/src/main/res/layout/calendar_body.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/calendar_background_color"
android:orientation="vertical">
android:orientation="vertical"
android:padding="10dp">

<GridView
android:id="@+id/calendar_body_week"
Expand All @@ -28,7 +29,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/calendar_body_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none" />

Expand Down
Loading

0 comments on commit 8abb24d

Please sign in to comment.