Skip to content

Commit

Permalink
数字背景
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Sep 3, 2019
1 parent 3f4e6b9 commit 34a4781
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.necer.entity.CalendarDate;
import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;

import org.joda.time.LocalDate;

Expand Down Expand Up @@ -42,6 +43,11 @@ private Paint getPaint() {
return paint;
}

@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {

}

@Override
public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) {
drawSelectBg(canvas, rectF, localDate, true, selectedDateList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;

import org.joda.time.LocalDate;

Expand All @@ -27,6 +28,11 @@ public StretchPainter(Context context) {
}


@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {

}

@Override
public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) {
canvas.drawRect(rectF, mBgPaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.necer.calendar.ICalendar;
import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;

import org.joda.time.LocalDate;

Expand Down Expand Up @@ -68,6 +69,11 @@ private Paint getPaint() {
}


@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {

}

@Override
public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) {
drawSelectBg(canvas, rectF, selectedDateList.contains(localDate), true);
Expand Down
10 changes: 10 additions & 0 deletions ncalendar/src/main/java/com/necer/calendar/BaseCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,23 @@ public CalendarPainter getCalendarPainter() {
return mCalendarPainter;
}


@Override
public void updateSlideDistance(int currentDistance) {
CalendarView currectCalendarView = findViewWithTag(getCurrentItem());
if (currectCalendarView != null) {
currectCalendarView.updateSlideDistance(currentDistance);
}
}

//月周切换时交换数据,保证月日历和周日历有相同的选中日期
public void exchangeSelectDateList(List<LocalDate> dateList) {
mAllSelectDateList.clear();
mAllSelectDateList.addAll(dateList);
notifyCalendar();
}


public void setOnMWDateChangeListener(OnMWDateChangeListener onMWDateChangeListener) {
this.mOnMWDateChangeListener = onMWDateChangeListener;
}
Expand Down
3 changes: 3 additions & 0 deletions ncalendar/src/main/java/com/necer/calendar/ICalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@ public interface ICalendar {
//获取当前页面的数据 如果是月周折叠日历 周状态下获取的是一周的数据,月状态下获取的一月的数据
List<LocalDate> getCurrectDateList();


void updateSlideDistance(int currentDistance);

}
8 changes: 7 additions & 1 deletion ncalendar/src/main/java/com/necer/calendar/NCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,12 @@ public void setOnCalendarMultipleChangedListener(OnCalendarMultipleChangedListen
weekCalendar.setOnCalendarMultipleChangedListener(onCalendarMultipleChangedListener);
}

@Override
public void updateSlideDistance(int currentDistance) {
monthCalendar.updateSlideDistance(currentDistance);
weekCalendar.updateSlideDistance(currentDistance);
}

@Override
public void setOnCalendarStateChangedListener(OnCalendarStateChangedListener onCalendarStateChangedListener) {
this.onCalendarStateChangedListener = onCalendarStateChangedListener;
Expand Down Expand Up @@ -771,7 +777,7 @@ protected boolean isMonthCalendarWeekState() {
//滑动中 包含跟随手势和自动滑动
protected void scrolling(float dy) {
setWeekVisible(dy > 0);

updateSlideDistance((int) childView.getY());
if (onCalendarScrollingListener != null) {
onCalendarScrollingListener.onCalendarScrolling(dy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.graphics.Canvas;
import android.graphics.RectF;

import com.necer.calendar.BaseCalendar;
import com.necer.view.CalendarView;

import org.joda.time.LocalDate;

import java.util.List;
Expand All @@ -13,6 +16,8 @@
public interface CalendarPainter {


void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance);

//绘制今天的日期
void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList);

Expand All @@ -26,4 +31,5 @@ public interface CalendarPainter {
void onDrawDisableDate(Canvas canvas, RectF rectF, LocalDate localDate);



}
26 changes: 26 additions & 0 deletions ncalendar/src/main/java/com/necer/painter/InnerPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.util.Log;

import com.necer.calendar.ICalendar;
import com.necer.entity.CalendarDate;
import com.necer.utils.Attrs;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;
import com.necer.view.MonthView;

import org.joda.time.LocalDate;

Expand All @@ -26,6 +30,7 @@ public class InnerPainter implements CalendarPainter {
private Attrs mAttrs;
protected Paint mTextPaint;
protected Paint mCirclePaint;
protected Paint mBgPaint;

private int noAlphaColor = 255;

Expand Down Expand Up @@ -59,6 +64,11 @@ public InnerPainter(ICalendar calendar) {
for (int i = 0; i < workdayList.size(); i++) {
mWorkdayList.add(new LocalDate(workdayList.get(i)));
}

mBgPaint = getPaint();
mBgPaint.setTextSize(100);
mBgPaint.setColor(Color.BLUE);
mBgPaint.setTypeface(Typeface.DEFAULT_BOLD);
}


Expand All @@ -70,6 +80,22 @@ private Paint getPaint() {
}


@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {
Log.e("aa", "InnerPainter:calendarView:" + calendarView);
Log.e("aa", "InnerPainter:localDate:" + localDate);
Log.e("aa", "InnerPainter:totalDistance:" + totalDistance);
Log.e("aa", "InnerPainter:currentDistance:" + currentDistance);
Log.e("aa", "InnerPainter:rectF:" + rectF.bottom);

if (calendarView instanceof MonthView) {
// canvas.drawRect(rectF,mBgPaint);
canvas.drawText(localDate.getMonthOfYear() + "", rectF.centerX(), getBaseLineY(rectF), mBgPaint);

}

}

@Override
public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectDateList) {
if (selectDateList.contains(localDate)) {
Expand Down
30 changes: 29 additions & 1 deletion ncalendar/src/main/java/com/necer/view/CalendarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -27,12 +28,15 @@ public abstract class CalendarView extends View {
private int mLineNum;//行数
protected LocalDate mInitialDate;//当前页面的初始化日期
protected List<RectF> mRectFList;//点击用的矩形集合
protected RectF mBgRectF;//日历背景集合
protected List<LocalDate> mDateList;//页面的数据集合
private List<LocalDate> mAllSelectListDate;//当前页面选中的日期
protected BaseCalendar mCalendar;
protected LocalDate mStartDate;
protected LocalDate mEndDate;

private int mCurrentDistance;//折叠日历滑动当前的距离

public CalendarView(Context context, ViewGroup container, LocalDate initialDate, List<LocalDate> dateList) {
super(context);
this.mInitialDate = initialDate;
Expand All @@ -49,12 +53,32 @@ public CalendarView(Context context, ViewGroup container, LocalDate initialDate,
for (int i = 0; i < mDateList.size(); i++) {
mRectFList.add(new RectF());
}
mBgRectF = new RectF();
}


@Override
protected void onDraw(Canvas canvas) {

CalendarPainter calendarPainter = mCalendar.getCalendarPainter();
//绘制背景
drawBg(canvas, calendarPainter);
//绘制日期
drawDate(canvas, calendarPainter);
}

//绘制背景
private void drawBg(Canvas canvas, CalendarPainter calendarPainter) {
mBgRectF.set(0f, 0f, getMeasuredWidth(), getMeasuredHeight());
Log.e("aa", "drawBg:::" + getMeasuredHeight());
calendarPainter.onDrawCalendarBackground(this, canvas, mBgRectF, getMiddleLocalDate(), getMeasuredHeight(), mCurrentDistance);

}


//绘制日期
private void drawDate(Canvas canvas, CalendarPainter calendarPainter) {

for (int i = 0; i < mLineNum; i++) {
for (int j = 0; j < 7; j++) {
RectF rectF = mRectFList.get(i * 7 + j);
Expand All @@ -75,7 +99,6 @@ protected void onDraw(Canvas canvas) {
}

//开始绘制
CalendarPainter calendarPainter = mCalendar.getCalendarPainter();
LocalDate localDate = mDateList.get(i * 7 + j);
//在可用区间内的正常绘制,
if (!(localDate.isBefore(mStartDate) || localDate.isAfter(mEndDate))) {
Expand Down Expand Up @@ -186,6 +209,11 @@ public List<LocalDate> getCurrentSelectDateList() {
return currentSelectDateList;
}

public void updateSlideDistance(int currentDistance) {
this.mCurrentDistance = currentDistance;
invalidate();
}

//获取当前页面的日期
public List<LocalDate> getCurrentDateList() {
return mDateList;
Expand Down

0 comments on commit 34a4781

Please sign in to comment.