Skip to content

Commit

Permalink
support auto select day attr
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Jul 3, 2019
1 parent a80fdbf commit 67b5c73
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 20 deletions.
7 changes: 7 additions & 0 deletions QUESTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,13 @@ int differ(Calendar calendar);
<!-- when select_mode=range_mode -->
<attr name="min_select_range" format="integer" />
<attr name="max_select_range" format="integer" />

<!-- auto select day -->
<attr name="month_view_auto_select_day">
<enum name="first_day_of_month" value="0" />
<enum name="last_select_day" value="1" />
<enum name="last_select_day_ignore_current" value="2" />
</attr>
</declare-styleable>

```
Expand Down
7 changes: 7 additions & 0 deletions QUESTION_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ int differ(Calendar calendar);//日期运算,相差多少天
<!-- 当 select_mode=range_mode -->
<attr name="min_select_range" format="integer" />
<attr name="max_select_range" format="integer" />

<!-- auto select day -->
<attr name="month_view_auto_select_day">
<enum name="first_day_of_month" value="0" />
<enum name="last_select_day" value="1" />
<enum name="last_select_day_ignore_current" value="2" />
</attr>
</declare-styleable>

```
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ You can't think of the calendar can be so elegant!

### Gradle
```
compile 'com.haibin:calendarview:3.6.3'
compile 'com.haibin:calendarview:3.6.4'
```

```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.6.3</version>
<version>3.6.4</version>
<type>pom</type>
</dependency>
```
Expand Down
8 changes: 4 additions & 4 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ Android上一个优雅、高度自定义、性能高效的日历控件,完美

插拔式设计:好比插座一样,插上灯泡就会亮,插上风扇就会转,看用户需求什么而不是看插座有什么,只要是电器即可。此框架使用插拔式,既可以在编译时指定年月日视图,如:app:month_view="xxx.xxx.MonthView.class",也可在运行时动态更换年月日视图,如:CalendarView.setMonthViewClass(MonthView.Class),从而达到UI即插即用的效果,相当于框架不提供UI实现,让UI都由客户端实现,不至于日历UI都千篇一律,只需遵守插拔式接口即可随意定制,自由化程度非常高。

[**English Version**](https://github.com/huanghaibin-dev/CalendarView/blob/master/QUESTION_ZH.md)
[**English Version**](https://github.com/huanghaibin-dev/CalendarView/blob/master/QUESTION.md)

[**详细介绍**](https://github.com/huanghaibin-dev/CalendarView/blob/master/QUESTION_ZH.md)

### Gradle
```
compile 'com.haibin:calendarview:3.6.3
compile 'com.haibin:calendarview:3.6.4
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.6.3</version>
<version>3.6.4</version>
<type>pom</type>
</dependency>
```
Expand Down Expand Up @@ -54,7 +54,7 @@ compile 'com.haibin:calendarview:3.6.3
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/year_view.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/range.png" height="650"/>
### 中国式变态需求风格
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/custom_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/custom_shrink.png" height="650"/>
### 收缩展开的魅族风格效果
### 收缩展开的魅族风格效果a
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/meizu_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/meizu_shrink.png" height="650"/>
### 全屏和多彩风格
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/full_calendar.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/color_expand.png" height="650"/>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
app:year_view_scheme_color="#f17706"
app:year_view_week_height="0dp"
app:year_view_week_text_color="#666666"
app:month_view_auto_select_day="last_select_day_ignore_current"
app:year_view_week_text_size="7sp" />


Expand Down
4 changes: 2 additions & 2 deletions calendarview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdkVersion 14
//noinspection OldTargetApi
targetSdkVersion 23
versionCode 363
versionName "3.6.3"
versionCode 364
versionName "3.6.4"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ static Calendar getFirstCalendarFromMonthViewPager(int position, CalendarViewDel
Calendar calendar = new Calendar();
calendar.setYear((position + delegate.getMinYearMonth() - 1) / 12 + delegate.getMinYear());
calendar.setMonth((position + delegate.getMinYearMonth() - 1) % 12 + 1);
if (delegate.getDefaultCalendarSelectDay() == CalendarViewDelegate.LAST_MONTH_VIEW_SELECT_DAY) {
if (delegate.getDefaultCalendarSelectDay() != CalendarViewDelegate.FIRST_DAY_OF_MONTH) {
int monthDays = getMonthDaysCount(calendar.getYear(), calendar.getMonth());
Calendar indexCalendar = delegate.mIndexCalendar;
calendar.setDay(indexCalendar == null || indexCalendar.getDay() == 0 ? 1 :
Expand Down Expand Up @@ -760,7 +760,8 @@ static Calendar getFirstCalendarFromMonthViewPager(int position, CalendarViewDel
* @return 获取边界访问日期
*/
static Calendar getRangeEdgeCalendar(Calendar calendar, CalendarViewDelegate delegate) {
if (CalendarUtil.isCalendarInRange(delegate.getCurrentDay(), delegate)) {
if (CalendarUtil.isCalendarInRange(delegate.getCurrentDay(), delegate)
&& delegate.getDefaultCalendarSelectDay() != CalendarViewDelegate.LAST_MONTH_VIEW_SELECT_DAY_IGNORE_CURRENT) {
return delegate.createCurrentDate();
}
if (isCalendarInRange(calendar, delegate)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,17 @@ public final void setYearViewScrollable(boolean yearViewScrollable) {


public final void setDefaultMonthViewSelectDay(){
mDelegate.setDefaultCalendarSelectDay(CalendarViewDelegate.DEFAULT_MONTH_VIEW_SELECT_DAY);
mDelegate.setDefaultCalendarSelectDay(CalendarViewDelegate.FIRST_DAY_OF_MONTH);
}

public final void setLastMonthViewSelectDay(){
mDelegate.setDefaultCalendarSelectDay(CalendarViewDelegate.LAST_MONTH_VIEW_SELECT_DAY);
}

public final void setLastMonthViewSelectDayIgnoreCurrent(){
mDelegate.setDefaultCalendarSelectDay(CalendarViewDelegate.LAST_MONTH_VIEW_SELECT_DAY_IGNORE_CURRENT);
}

/**
* 清除选择范围
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ final class CalendarViewDelegate {
static final int WEEK_START_WITH_SAT = 7;

/**
* 默认选择日期1号
* 默认选择日期1号first_day_of_month
*/
static final int DEFAULT_MONTH_VIEW_SELECT_DAY = 0;
static final int FIRST_DAY_OF_MONTH = 0;

/**
* 跟随上个月
* 跟随上个月last_select_day
*/
static final int LAST_MONTH_VIEW_SELECT_DAY = 1;

/**
* 跟随上个月last_select_day_ignore_current忽视今天
*/
static final int LAST_MONTH_VIEW_SELECT_DAY_IGNORE_CURRENT = 2;

private int mDefaultCalendarSelectDay;

Expand Down Expand Up @@ -416,7 +420,7 @@ final class CalendarViewDelegate {
mYearViewScrollable = array.getBoolean(R.styleable.CalendarView_year_view_scrollable, true);

mDefaultCalendarSelectDay = array.getInt(R.styleable.CalendarView_month_view_auto_select_day,
1);
FIRST_DAY_OF_MONTH);

mMonthViewShowMode = array.getInt(R.styleable.CalendarView_month_view_show_mode, MODE_ALL_MONTH);
mWeekStart = array.getInt(R.styleable.CalendarView_week_start_with, WEEK_START_WITH_SUN);
Expand Down Expand Up @@ -1075,11 +1079,13 @@ final List<Calendar> getSelectCalendarRange() {
calendar.setYear(date.get(java.util.Calendar.YEAR));
calendar.setMonth(date.get(java.util.Calendar.MONTH) + 1);
calendar.setDay(date.get(java.util.Calendar.DAY_OF_MONTH));
LunarCalendar.setupLunarCalendar(calendar);
updateCalendarScheme(calendar);
if (mCalendarInterceptListener != null &&
mCalendarInterceptListener.onCalendarIntercept(calendar)) {
continue;
}
LunarCalendar.setupLunarCalendar(calendar);

calendars.add(calendar);
}
addSchemesFromMap(calendars);
Expand Down
5 changes: 3 additions & 2 deletions calendarview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@

<!-- auto select day -->
<attr name="month_view_auto_select_day">
<enum name="first_month_of_day" value="0" />
<enum name="last_select" value="1" />
<enum name="first_day_of_month" value="0" />
<enum name="last_select_day" value="1" />
<enum name="last_select_day_ignore_current" value="2" />
</attr>
</declare-styleable>

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ org.gradle.jvmargs=-Xmx1536m
POM_BINTRAY_NAME=com.haibin:calendarview
POM_DESCRIPTION=A very good CalendarView for Android.
POM_ARTIFACT_ID=calendarview
VERSION_NAME=3.6.3
VERSION_CODE=3.6.3
VERSION_NAME=3.6.4
VERSION_CODE=3.6.4
POM_BINTRAY_PRPO=maven
POM_PACKAGING=aar
POM_NAME=calendarview
Expand Down

0 comments on commit 67b5c73

Please sign in to comment.