Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Aug 15, 2019
1 parent 7efd814 commit c3dde1b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 20 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
minSdkVersion 15
targetSdkVersion 27
versionCode 2
versionName "4.3.3"
versionName "4.3.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
innerPainter.setReplaceLunarStrMap(strMap);

Map<String, Integer> colorMap = new HashMap<>();
colorMap.put("2019-07-25", Color.RED);
colorMap.put("2019-08-25", Color.RED);

colorMap.put("2019-07-5", Color.parseColor("#000000"));
colorMap.put("2019-08-5", Color.parseColor("#000000"));
innerPainter.setReplaceLunarColorMap(colorMap);


Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_miui10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
app:holidayColor="#519EDC"
app:lunarHolidayTextColor="#519EDC"
app:pointLocation="down"
app:selectSolarTextColorColor="#00ff00"
app:selectLunarTextColor="#00ff00"
app:selectCircleColor="#398FE9"
app:solarHolidayTextColor="#519EDC"
app:solarTermTextColor="#519EDC"
Expand Down
4 changes: 2 additions & 2 deletions ncalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "4.3.3"
versionName "4.3.4"
}
}

Expand All @@ -23,7 +23,7 @@ publish {
repoName = 'maven'//bintray仓库
groupId = 'com.necer.ncalendar'//jcenter上的路径
artifactId = 'ncalendar'//项目名称
publishVersion = '4.3.3'//版本号
publishVersion = '4.3.4'//版本号
desc = 'NCalendar'
website = 'https://github.com/yannecer/NCalendar'
}
7 changes: 3 additions & 4 deletions ncalendar/src/main/java/com/necer/calendar/NCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.support.annotation.Nullable;
import android.support.v4.view.NestedScrollingParent;
import android.util.AttributeSet;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -305,7 +306,7 @@ public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {

@Override
public boolean onNestedPreFling(View target, float velocityX, float velocityY) {
return false;
return childView.getY() != weekHeight;
}

@Override
Expand All @@ -314,10 +315,8 @@ public void onStopNestedScroll(View target) {
//此时 childViewY 必为 3个标志位之一,判断不为这三个数值就自动滑动

int childViewY = (int) childView.getY();
int monthCalendarY = (int) monthCalendar.getY();

if ((childViewY != monthHeight && childViewY != weekHeight && childViewY != stretchMonthHeight) ||
(monthCalendarY != 0 && monthCalendarY != monthCalendar.getPivotDistanceFromTop())) {
if (childViewY != monthHeight && childViewY != weekHeight && childViewY != stretchMonthHeight) {
autoScroll();
} else {
callBackCalenadarState();
Expand Down
28 changes: 17 additions & 11 deletions ncalendar/src/main/java/com/necer/painter/InnerPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<Lo
if (selectDateList.contains(localDate)) {
drawSelectBg(canvas, rectF, noAlphaColor, true);
drawSolar(canvas, rectF, localDate, noAlphaColor, true, true);
drawLunar(canvas, rectF, true, noAlphaColor, localDate);
drawLunar(canvas, rectF, localDate, noAlphaColor, true, true);
drawPoint(canvas, rectF, true, noAlphaColor, localDate);
drawHolidays(canvas, rectF, true, noAlphaColor, localDate);
} else {
drawSolar(canvas, rectF, localDate, noAlphaColor, false, true);
drawLunar(canvas, rectF, false, noAlphaColor, localDate);
drawLunar(canvas, rectF, localDate, noAlphaColor, false, true);
drawPoint(canvas, rectF, false, noAlphaColor, localDate);
drawHolidays(canvas, rectF, false, noAlphaColor, localDate);
}
Expand All @@ -92,12 +92,12 @@ public void onDrawCurrentMonthOrWeek(Canvas canvas, RectF rectF, LocalDate local
if (selectDateList.contains(localDate)) {
drawSelectBg(canvas, rectF, noAlphaColor, false);
drawSolar(canvas, rectF, localDate, noAlphaColor, true, false);
drawLunar(canvas, rectF, false, noAlphaColor, localDate);
drawLunar(canvas, rectF, localDate, noAlphaColor, true, false);
drawPoint(canvas, rectF, false, noAlphaColor, localDate);
drawHolidays(canvas, rectF, false, noAlphaColor, localDate);
} else {
drawSolar(canvas, rectF, localDate, noAlphaColor, false, false);
drawLunar(canvas, rectF, false, noAlphaColor, localDate);
drawLunar(canvas, rectF, localDate, noAlphaColor, false, false);
drawPoint(canvas, rectF, false, noAlphaColor, localDate);
drawHolidays(canvas, rectF, false, noAlphaColor, localDate);
}
Expand All @@ -109,13 +109,12 @@ public void onDrawLastOrNextMonth(Canvas canvas, RectF rectF, LocalDate localDat
if (selectDateList.contains(localDate)) {
drawSelectBg(canvas, rectF, mAttrs.alphaColor, false);
drawSolar(canvas, rectF, localDate, mAttrs.alphaColor, true, false);
drawLunar(canvas, rectF, false, mAttrs.alphaColor, localDate);
drawLunar(canvas, rectF, localDate, mAttrs.alphaColor, true, false);
drawPoint(canvas, rectF, false, mAttrs.alphaColor, localDate);
drawHolidays(canvas, rectF, false, mAttrs.alphaColor, localDate);

} else {
drawSolar(canvas, rectF, localDate, mAttrs.alphaColor, false, false);
drawLunar(canvas, rectF, false, mAttrs.alphaColor, localDate);
drawLunar(canvas, rectF, localDate, mAttrs.alphaColor, false, false);
drawPoint(canvas, rectF, false, mAttrs.alphaColor, localDate);
drawHolidays(canvas, rectF, false, mAttrs.alphaColor, localDate);
}
Expand All @@ -125,7 +124,7 @@ public void onDrawLastOrNextMonth(Canvas canvas, RectF rectF, LocalDate localDat
@Override
public void onDrawDisableDate(Canvas canvas, RectF rectF, LocalDate localDate) {
drawSolar(canvas, rectF, localDate, mAttrs.disabledAlphaColor, false, false);
drawLunar(canvas, rectF, false, mAttrs.disabledAlphaColor, localDate);
drawLunar(canvas, rectF, localDate, mAttrs.disabledAlphaColor, false, false);
drawPoint(canvas, rectF, false, mAttrs.disabledAlphaColor, localDate);
drawHolidays(canvas, rectF, false, mAttrs.disabledAlphaColor, localDate);
drawStretchText(canvas, rectF, mAttrs.disabledAlphaColor, localDate);
Expand All @@ -145,7 +144,7 @@ private void drawSelectBg(Canvas canvas, RectF rectF, int alphaColor, boolean is
//绘制公历
private void drawSolar(Canvas canvas, RectF rectF, LocalDate date, int alphaColor, boolean isSelect, boolean isToday) {
if (isSelect) {
mTextPaint.setColor(isToday ? mAttrs.todaySolarSelectTextColor : mAttrs.solarTextColor);
mTextPaint.setColor(isToday ? mAttrs.todaySolarSelectTextColor : mAttrs.selectSolarTextColorColor);
} else {
mTextPaint.setColor(isToday ? mAttrs.todaySolarTextColor : mAttrs.solarTextColor);
}
Expand All @@ -155,8 +154,9 @@ private void drawSolar(Canvas canvas, RectF rectF, LocalDate date, int alphaColo
}

//绘制农历
private void drawLunar(Canvas canvas, RectF rectF, boolean isTodaySelect, int alphaColor, LocalDate localDate) {
private void drawLunar(Canvas canvas, RectF rectF, LocalDate localDate, int alphaColor, boolean isSelect, boolean isToday) {
if (mAttrs.isShowLunar) {
boolean isTodaySelect = isSelect && isToday;
CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate);
//优先顺序 替换的文字、农历节日、节气、公历节日、正常农历日期
String lunarString = mReplaceLunarStrMap.get(calendarDate.localDate);
Expand All @@ -176,7 +176,13 @@ private void drawLunar(Canvas canvas, RectF rectF, boolean isTodaySelect, int al
}
}
Integer color = mReplaceLunarColorMap.get(calendarDate.localDate);
mTextPaint.setColor(color == null ? (isTodaySelect ? mAttrs.todaySelectContrastColor : mAttrs.lunarTextColor) : color);
if (color == null) {
if (isSelect) {
mTextPaint.setColor(isToday ? mAttrs.todaySelectContrastColor : mAttrs.selectLunarTextColor);
}
} else {
mTextPaint.setColor(color);
}
mTextPaint.setTextSize(mAttrs.lunarTextSize);
mTextPaint.setAlpha(alphaColor);
canvas.drawText(lunarString, rectF.centerX(), rectF.centerY() + mAttrs.lunarDistance, mTextPaint);
Expand Down
2 changes: 2 additions & 0 deletions ncalendar/src/main/java/com/necer/utils/Attrs.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class Attrs {
public int lunarHolidayTextColor;
public int solarTermTextColor;
public int selectCircleColor;
public int selectSolarTextColorColor;//选中公历颜色
public int selectLunarTextColor;//选中农历颜色
public float solarTextSize;
public float lunarTextSize;
public float lunarDistance;//农历到文字中心的距离
Expand Down
2 changes: 2 additions & 0 deletions ncalendar/src/main/java/com/necer/utils/AttrsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public static Attrs getAttrs(Context context, AttributeSet attributeSet) {
TypedArray ta = context.obtainStyledAttributes(attributeSet, R.styleable.NCalendar);

attrs.solarTextColor = ta.getColor(R.styleable.NCalendar_solarTextColor, context.getResources().getColor(R.color.solarTextColor));
attrs.selectSolarTextColorColor = ta.getColor(R.styleable.NCalendar_selectSolarTextColorColor, context.getResources().getColor(R.color.solarTextColor));
attrs.todaySolarTextColor = ta.getColor(R.styleable.NCalendar_todaySolarTextColor, context.getResources().getColor(R.color.todaySolarTextColor));
attrs.todaySolarSelectTextColor = ta.getColor(R.styleable.NCalendar_todaySolarSelectTextColor, context.getResources().getColor(R.color.white));
attrs.lunarTextColor = ta.getColor(R.styleable.NCalendar_lunarTextColor, context.getResources().getColor(R.color.lunarTextColor));
attrs.selectLunarTextColor = ta.getColor(R.styleable.NCalendar_selectLunarTextColor, context.getResources().getColor(R.color.lunarTextColor));
attrs.solarHolidayTextColor = ta.getColor(R.styleable.NCalendar_solarHolidayTextColor, context.getResources().getColor(R.color.solarHolidayTextColor));
attrs.lunarHolidayTextColor = ta.getColor(R.styleable.NCalendar_lunarHolidayTextColor, context.getResources().getColor(R.color.lunarHolidayTextColor));
attrs.solarTermTextColor = ta.getColor(R.styleable.NCalendar_solarTermTextColor, context.getResources().getColor(R.color.solarTermTextColor));
Expand Down
2 changes: 2 additions & 0 deletions ncalendar/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<attr name="lunarHolidayTextColor" format="color" />
<attr name="solarTermTextColor" format="color" />
<attr name="selectCircleColor" format="color" />
<attr name="selectSolarTextColorColor" format="color" />
<attr name="selectLunarTextColor" format="color" />
<attr name="todaySolarTextColor" format="color" />
<attr name="todaySolarSelectTextColor" format="color" />
<attr name="solarTextSize" format="dimension" />
Expand Down

0 comments on commit c3dde1b

Please sign in to comment.