Skip to content

Commit

Permalink
完善
Browse files Browse the repository at this point in the history
  • Loading branch information
doutuifei committed Mar 26, 2018
1 parent e52061c commit 3d3a948
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 13 deletions.
123 changes: 123 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,122 @@
[APK下载](https://w-5.net/YPqDk)

## 功能
* 默认显示6个月信息
* 连续选择
* 设置不可选项
* 自动调换开始和结束位置
* 回调和get获取选择的日期信息

## 方法
* addUnableDays(int days);
设置今天之后不可点击选择的天数

* resetState();
取消所有选中,但是不会取消不可点击的天数,可以使用
```addUnableDays(0);```

* 回调
```
setOnCalendarChange(new CalendarView.OnCalendarChange() {
@Override
public void onStart(DayBean dayBean) {
}
@Override
public void onEnd(DayBean dayBean) {
}
@Override
public void onDays(int day) {
super.onDays(day);
}
});
```
>DayBean
```
public class DayBean {
private boolean isTodayDay;
private int month;
private int year;
private int day;
public DayBean() {
}
public boolean isTodayDay() {
return isTodayDay;
}
public void setTodayDay(boolean todayDay) {
isTodayDay = todayDay;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
@Override
public String toString() {
return year + "-" + month + "-" + day;
}
public Calendar getCalendar() {
return CalendarUtils.getCurreCalendar(year, month - 1, day);
}
}
```

* get方法

```
/**
* 获取开始日期
*
* @return
*/
public SelectBean getSelectStartDays() {
return startSelectBean;
}
/**
* 获取结束日期
*
* @return
*/
public SelectBean getSelectEndDays() {
return endSelectBean;
}
/**
* 获取选择天数
*
* @return
*/
public int getSelectDays() {
return selectDays;
}
```

## 使用

### Gradle
Expand Down Expand Up @@ -49,3 +160,15 @@ dependencies {
<version>0.1.0</version>
</dependency>
```

## 混淆
```
-keep class com.chad.library.adapter.** {
*;
}
-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
-keep public class * extends com.chad.library.adapter.base.BaseViewHolder
-keepclassmembers class **$** extends com.chad.library.adapter.base.BaseViewHolder {
<init>(...);
}
```
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
defaultConfig {
applicationId "com.muzi.verticalcalendar"
minSdkVersion 19
targetSdkVersion 27
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -27,5 +27,7 @@ dependencies {
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':library')
// compile project(':library')
compile 'com.github.mzyq:VerticalCalendar:0.1.0'
}

24 changes: 24 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,27 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

-keep class com.chad.library.adapter.** {
*;
}
-keep public class * extends com.chad.library.adapter.base.BaseQuickAdapter
-keep public class * extends com.chad.library.adapter.base.BaseViewHolder
-keepclassmembers class **$** extends com.chad.library.adapter.base.BaseViewHolder {
<init>(...);
}
-keep class **.R$* {*;}
-keep class android.support.** {*;}
-keepclasseswithmembers class * { # 保持自定义控件类不被混淆
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {# 保持自定义控件类不被混淆
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity { # 保持自定义控件类不被混淆
public void *(android.view.View);
}
-keep class com.muzi.library.bean.**{
*;
}
-dontoptimize
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.muzi.library.CalendarView;
import com.muzi.library.bean.DayBean;
Expand Down Expand Up @@ -36,22 +35,20 @@ public void onClick(View v) {
calendarView.addUnableDays(Integer.parseInt(editText.getText().toString().trim()));
}
});
calendarView.resetState();

calendarView.setOnCalendarChange(new CalendarView.OnCalendarChange() {
@Override
public void onStart(DayBean dayBean) {

}

@Override
public void onEnd(DayBean dayBean) {

}

@Override
public void onDays(int day) {
super.onDays(day);
Toast.makeText(MainActivity.this, "选择了:" + day + "天", Toast.LENGTH_SHORT).show();
}
});
}
Expand Down
9 changes: 9 additions & 0 deletions library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-keepclasseswithmembers class * {
public <init>(android.content.Context);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
5 changes: 3 additions & 2 deletions library/src/main/java/com/muzi/library/CalendarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void initCalendarList() {

//是否是today
if (CalendarUtils.equalsCalendar(curreCalendar, todayCalendar)) {
dayBean.setCurreDay(true);
dayBean.setTodayDay(true);
dayBean.setContent(getContext().getString(R.string.today));
}

Expand Down Expand Up @@ -462,8 +462,9 @@ private void handleListener() {
if (startSelectBean != null && endSelectBean != null) {
selectDays = CalendarUtils.differentDays(startSelectBean.getDayBean().getCalendar(),
endSelectBean.getDayBean().getCalendar());
selectDays++;
if (onCalendarChange != null) {
onCalendarChange.onDays(selectDays + 1);
onCalendarChange.onDays(selectDays);
}
} else {
selectDays = 0;
Expand Down
10 changes: 5 additions & 5 deletions library/src/main/java/com/muzi/library/bean/DayBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DayBean implements Cloneable {
/**
* 是否今天
*/
private boolean isCurreDay;
private boolean isTodayDay;
/**
* 补全空白
*/
Expand Down Expand Up @@ -45,12 +45,12 @@ public DayBean(boolean isEmpty) {
this.isEmpty = isEmpty;
}

public boolean isCurreDay() {
return isCurreDay;
public boolean isTodayDay() {
return isTodayDay;
}

public void setCurreDay(boolean curreDay) {
isCurreDay = curreDay;
public void setTodayDay(boolean todayDay) {
isTodayDay = todayDay;
}

public String getWeek() {
Expand Down

0 comments on commit 3d3a948

Please sign in to comment.