Skip to content

Commit

Permalink
注释
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Mar 31, 2020
1 parent ac30a5c commit 02c1eca
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 85 deletions.
32 changes: 14 additions & 18 deletions ncalendar/src/main/java/com/necer/calendar/BaseCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ private void initAdapter() {
}

if (mStartDate.isAfter(mEndDate)) {
throw new IllegalArgumentException("startDate必须在endDate之前");
throw new IllegalArgumentException(getContext().getString(R.string.N_start_after_end));
}

if (mStartDate.isBefore(new LocalDate(mDefaultStartDate))) {
throw new IllegalArgumentException("startDate必须在1901-01-01之后");
throw new IllegalArgumentException(getContext().getString(R.string.N_start_before_19010101));
}

if (mEndDate.isAfter(new LocalDate(mDefaultEndDateDate))) {
throw new IllegalArgumentException("endDate必须在2099-12-31之前");
throw new IllegalArgumentException(getContext().getString(R.string.N_end_after_20991231));
}

if (mStartDate.isAfter(mInitializeDate) || mEndDate.isBefore(mInitializeDate)) {
throw new IllegalArgumentException("日期区间必须包含初始化日期");
throw new IllegalArgumentException(getContext().getString(R.string.N_initialize_date_illegal));
}

mCalendarPagerSize = getTwoDateCount(mStartDate, mEndDate, mFirstDayOfWeek) + 1;
Expand All @@ -158,7 +158,7 @@ public void setDateInterval(String startFormatDate, String endFormatDate) {
mStartDate = new LocalDate(startFormatDate);
mEndDate = new LocalDate(endFormatDate);
} catch (Exception e) {
throw new IllegalArgumentException("startDate、endDate需要 yyyy-MM-dd 格式的日期");
throw new IllegalArgumentException(getContext().getString(R.string.N_date_format_illegal));
}
initAdapter();
}
Expand All @@ -168,7 +168,7 @@ public void setInitializeDate(String formatInitializeDate) {
try {
mInitializeDate = new LocalDate(formatInitializeDate);
} catch (Exception e) {
throw new IllegalArgumentException("setInitializeDate的参数需要 yyyy-MM-dd 格式的日期");
throw new IllegalArgumentException(getContext().getString(R.string.N_date_format_illegal));
}
initAdapter();
}
Expand All @@ -180,7 +180,7 @@ public void setDateInterval(String startFormatDate, String endFormatDate, String
mEndDate = new LocalDate(endFormatDate);
mInitializeDate = new LocalDate(formatInitializeDate);
} catch (Exception e) {
throw new IllegalArgumentException("setInitializeDate的参数需要 yyyy-MM-dd 格式的日期");
throw new IllegalArgumentException(getContext().getString(R.string.N_date_format_illegal));
}
initAdapter();
}
Expand Down Expand Up @@ -316,10 +316,6 @@ private void callBack() {
}


// public void setDateChangeBehavior(DateChangeBehavior dateChangeBehavior) {
// this.mDateChangeBehavior = dateChangeBehavior;
// }

@Override
public void notifyCalendar() {
for (int i = 0; i < getChildCount(); i++) {
Expand Down Expand Up @@ -362,7 +358,7 @@ public void toLastPager() {

@Override
public void toToday() {
jump(new LocalDate(), true,DateChangeBehavior.API);
jump(new LocalDate(), true, DateChangeBehavior.API);
}


Expand All @@ -372,10 +368,10 @@ public void jumpDate(String formatDate) {
try {
jumpDate = new LocalDate(formatDate);
} catch (Exception e) {
throw new IllegalArgumentException("jumpDate的参数需要 yyyy-MM-dd 格式的日期");
throw new IllegalArgumentException(getContext().getString(R.string.N_date_format_illegal));
}

jump(jumpDate, true,DateChangeBehavior.API);
jump(jumpDate, true, DateChangeBehavior.API);
}


Expand All @@ -385,9 +381,9 @@ public void jumpDate(int year, int month, int day) {
try {
jumpDate = new LocalDate(year, month, day);
} catch (Exception e) {
throw new IllegalArgumentException("jumpDate的参数需要正确的年月日数据");
throw new IllegalArgumentException("");
}
jump(jumpDate, true,DateChangeBehavior.API);
jump(jumpDate, true, DateChangeBehavior.API);
}

@Override
Expand All @@ -396,9 +392,9 @@ public void jumpMonth(int year, int month) {
try {
jumpDate = new LocalDate(year, month, 1);
} catch (Exception e) {
throw new IllegalArgumentException("jumpDate的参数需要正确的年月日数据");
throw new IllegalArgumentException(getContext().getString(R.string.N_date_format_jump));
}
jump(jumpDate, mCheckModel == CheckModel.SINGLE_DEFAULT_CHECKED,DateChangeBehavior.API);
jump(jumpDate, mCheckModel == CheckModel.SINGLE_DEFAULT_CHECKED, DateChangeBehavior.API);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion ncalendar/src/main/java/com/necer/calendar/EmuiCalendar.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.necer.calendar;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.util.AttributeSet;

import com.necer.enumeration.CalendarState;
Expand All @@ -20,7 +22,7 @@ public EmuiCalendar(@NonNull Context context, @Nullable AttributeSet attrs) {

@Override
protected float getMonthCalendarAutoWeekEndY() {
return -monthHeight * 4 / 5;
return -monthHeight * 4.0f / 5.0f;
}

@Override
Expand Down
61 changes: 21 additions & 40 deletions ncalendar/src/main/java/com/necer/calendar/ICalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public interface ICalendar {
*/
void setCheckMode(CheckModel checkModel);

/**
* 获取日历的选中模式 折叠日历中用到
*/
CheckModel getCheckModel();

/**
Expand All @@ -42,8 +45,6 @@ public interface ICalendar {

/**
* 默认选中时,是否翻页选中第一个,只在checkModel==SINGLE_DEFAULT_CHECKED有效
*
* @param isDefaultCheckedFirstDate
*/
void setDefaultCheckedFirstDate(boolean isDefaultCheckedFirstDate);

Expand All @@ -57,18 +58,11 @@ public interface ICalendar {

/**
* 跳转日期
*
* @param year
* @param month
* @param day
*/
void jumpDate(int year, int month, int day);

/**
* 跳转日期,跳转到对应月份
*
* @param year
* @param month
*/
void jumpMonth(int year, int month);

Expand All @@ -91,19 +85,19 @@ public interface ICalendar {
/**
* 设置自定义绘制类
*
* @param calendarPainter 实现CalendarPainter接口,自定义绘制
* @param calendarPainter 实现CalendarPainter接口
*/
void setCalendarPainter(CalendarPainter calendarPainter);

/**
* 设置自定义适配器 继承CalendarAdapter,实现对应方法,自定义
*
* @param calendarAdapter
* @param calendarAdapter 继承抽象类CalendarAdapter
*/
void setCalendarAdapter(CalendarAdapter calendarAdapter);

/**
* 刷新日历
* 刷新日历 刷新viewpager中存在的view
*/
void notifyCalendar();

Expand All @@ -117,108 +111,95 @@ public interface ICalendar {
/**
* 设置初始化日期和可用区间 必须为 yyyy-MM-dd 的字符串
*
* @param startFormatDate
* @param endFormatDate
* @param formatInitializeDate
* @param startFormatDate 日历开始日期 默认1901-01-01
* @param endFormatDate 日历结束日期 默认2099-12-31
* @param formatInitializeDate 初始化选日期
*/
void setDateInterval(String startFormatDate, String endFormatDate, String formatInitializeDate);

/**
* 设置可用区间 必须为 yyyy-MM-dd 的字符串
*
* @param startFormatDate
* @param endFormatDate
* @param startFormatDate 日历开始日期 默认1901-01-01
* @param endFormatDate 日历结束日期 默认2099-12-31
*/
void setDateInterval(String startFormatDate, String endFormatDate);

/**
* 单选日期变化监听
*
* @param onCalendarChangedListener
*/
void setOnCalendarChangedListener(OnCalendarChangedListener onCalendarChangedListener);

/**
* 多选日期变化监听
*
* @param onCalendarMultipleChangedListener
*/
void setOnCalendarMultipleChangedListener(OnCalendarMultipleChangedListener onCalendarMultipleChangedListener);

/**
* 设置点击了不可用日期监听
*
* @param onClickDisableDateListener
*/
void setOnClickDisableDateListener(OnClickDisableDateListener onClickDisableDateListener);

/**
* 获取xml参数
*
* @return
*/
Attrs getAttrs();

/**
* 获取绘制类
*
* @return
*/
CalendarPainter getCalendarPainter();

/**
* 获取适配器
*
* @return
*/
CalendarAdapter getCalendarAdapter();

/**
* 获取全部选中的日期集合
*
* @return
*/
List<LocalDate> getTotalCheckedDateList();

/**
* 获取当前页面选中的日期集合
*
* @return
*/
List<LocalDate> getCurrPagerCheckDateList();

/**
* 获取当前页面的日期集合 如果是月周折叠日历 周状态下获取的是一周的数据,月状态下获取的一月的数据
*
* @return
*/
List<LocalDate> getCurrPagerDateList();

/**
* 月周折叠日历滑动过程中的滑动距离
*
* @param currentDistance
* @param currentDistance 当前滑动的距离
*/
void updateSlideDistance(int currentDistance);

/**
* 设置日历上下月能否点击
*
* @param enable
*/
void setLastNextMonthClickEnable(boolean enable);


/**
* 设置日历是否可以左右滑动
*
* @param scrollEnable
*/
void setScrollEnable(boolean scrollEnable);


/**
* @param calendarBackground 实现了CalendarBackground接口的背景
* @throws IllegalAccessException 月周折叠日历不允许使用此方法
* 折叠日历请调用setMonthCalendarBackground()和setWeekCalendarBackground()
*/
void setCalendarBackground(CalendarBackground calendarBackground) throws IllegalAccessException;

/**
* @return 获取日历的背景
* @throws IllegalAccessException 月周折叠日历不允许使用此方法
*/
CalendarBackground getCalendarBackground() throws IllegalAccessException;


Expand Down
30 changes: 18 additions & 12 deletions ncalendar/src/main/java/com/necer/calendar/IICalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,50 +26,56 @@ public interface IICalendar extends ICalendar {
void toStretch();

/**
* 设置周 滑动到周位置固定
*
* @param isWeekHoldEnable
* 设置是否滑动到周位置固定
*/
void setWeekHoldEnable(boolean isWeekHoldEnable);

/**
* 设置月状态下 下拉拉伸
*
* @param isMonthStretchEnable
* 设置月状态下 是否可以下拉拉伸
*/
void setMonthStretchEnable(boolean isMonthStretchEnable);

/**
* 日历月周状态变化回调
*
* @param onCalendarStateChangedListener
*/
void setOnCalendarStateChangedListener(OnCalendarStateChangedListener onCalendarStateChangedListener);

/**
* 日历 月 周 拉伸 状态滑动监听
*
* @param onCalendarScrollingListener
*/
void setOnCalendarScrollingListener(OnCalendarScrollingListener onCalendarScrollingListener);

/**
* 设置日历状态
*
* @param calendarState
* @param calendarState WEEK 周
* MONTH 月
* MONTH_STRETCH 向下拉伸
*/
void setCalendarState(CalendarState calendarState);

/**
* 获取当前日历的状态
*
* @return CalendarState.MONTH==月视图 CalendarState.WEEK==周视图 CalendarState.MONTH_STRETCH==日历拉伸状态
* @return CalendarState.MONTH==月视图
* CalendarState.WEEK==周视图
* CalendarState.MONTH_STRETCH==日历拉伸状态
*/
CalendarState getCalendarState();


/**
* 月周折叠日历设置月日历背景
*
* @param calendarBackground 实现了CalendarBackground接口的日历背景
*/
void setMonthCalendarBackground(CalendarBackground calendarBackground);

/**
* 月周折叠日历设置周日历背景
*
* @param calendarBackground 实现了CalendarBackground接口的日历背景
*/
void setWeekCalendarBackground(CalendarBackground calendarBackground);

}
Loading

0 comments on commit 02c1eca

Please sign in to comment.