Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@

# CalenderView

[![](https://jitpack.io/v/michaellee123/CalendarView.svg)](https://jitpack.io/#michaellee123/CalendarView)

李某人套娃基于[CalenderView](https://github.com/angcyo/CalendarView)`3.7.1.37`的版本修改,实现了滚动年月标题吸顶。如图:

![](/png/gif_sticky_vertical_scroll.gif)

吸顶效果使用:[GroupedRecyclerViewAdapter](https://github.com/donkingliang/GroupedRecyclerViewAdapter),感谢🙏

使用方法,用`StickyVerticalCalendarView`替换掉原本的`VerticalCalendarView`即可。

---

分割线

---

基于[CalenderView](https://github.com/huanghaibin-dev/CalendarView)`3.7.1`的版本修改, 实现了如下功能:

- `垂直列表日历`: 基于`RecyclerView`实现
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.haibin.calendarview.BaseMonthView;
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;
import com.haibin.calendarview.StickyVerticalCalendarView;
import com.haibin.calendarview.VerticalCalendarView;
import com.haibin.calendarview.VerticalMonthRecyclerView;
import com.haibin.calendarviewproject.base.activity.BaseActivity;
Expand All @@ -32,7 +33,7 @@ public class VerticalActivity extends BaseActivity implements

TextView mTextCurrentDay;

VerticalCalendarView mCalendarView;
StickyVerticalCalendarView mCalendarView;

RelativeLayout mRelativeTool;
int doCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@

public class ColorfulMonthView extends MonthView {

private int mRadius;
private float mRadius;

public ColorfulMonthView(Context context) {
super(context);
}

@Override
protected void onPreviewHook() {
mRadius = Math.min(mItemWidth, mItemHeight) / 5 * 2;
mRadius = (Math.min(mItemWidth, mItemHeight) / 5 * 2);
}

/**
Expand All @@ -35,25 +35,25 @@ protected void onPreviewHook() {
* @return false 则不绘制onDrawScheme,因为这里背景色是互斥的
*/
@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme) {
float cx = x + mItemWidth / 2;
float cy = y + mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
return true;
}

@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
protected void onDrawScheme(Canvas canvas, Calendar calendar, float x, float y) {
float cx = x + mItemWidth / 2;
float cy = y + mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
}

@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
int cx = x + mItemWidth / 2;
int top = y - mItemHeight / 8;
protected void onDrawText(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme, boolean isSelected) {
float cx = x + mItemWidth / 2;
float top = y - mItemHeight / 8;
if (isSelected) {
canvas.drawText(String.valueOf(calendar.getDay()), cx, mTextBaseLine + top,
calendar.isCurrentDay() ? mCurDayTextPaint : mSelectTextPaint);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.haibin.calendarviewproject.colorful;

import android.content.Context;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.view.View;

import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.WeekView;
Expand All @@ -15,7 +13,7 @@

public class ColorfulWeekView extends WeekView {

private int mRadius;
private float mRadius;

public ColorfulWeekView(Context context) {
super(context);
Expand All @@ -30,7 +28,7 @@ public ColorfulWeekView(Context context) {

@Override
protected void onPreviewHook() {
mRadius = Math.min(mItemWidth, mItemHeight) / 5 * 2;
mRadius = (Math.min(mItemWidth, mItemHeight) / 5 * 2);
}

/**
Expand All @@ -43,26 +41,26 @@ protected void onPreviewHook() {
* @return false 则不绘制onDrawScheme,因为这里背景色是互斥的
*/
@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = mItemHeight / 2;
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, float x, boolean hasScheme) {
float cx = x + mItemWidth / 2;
float cy = mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
return true;
}


@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x) {
int cx = x + mItemWidth / 2;
int cy = mItemHeight / 2;
protected void onDrawScheme(Canvas canvas, Calendar calendar, float x) {
float cx = x + mItemWidth / 2;
float cy = mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
}

@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelected) {
int cx = x + mItemWidth / 2;
int top = -mItemHeight / 8;
protected void onDrawText(Canvas canvas, Calendar calendar, float x, boolean hasScheme, boolean isSelected) {
float cx = x + mItemWidth / 2;
float top = -mItemHeight / 8;
if (isSelected) {
canvas.drawText(String.valueOf(calendar.getDay()), cx, mTextBaseLine + top,
calendar.isCurrentDay() ? mCurDayTextPaint : mSelectTextPaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class CustomMonthView extends MonthView {

private int mRadius;
private float mRadius;

/**
* 自定义魅族标记的文本画笔
Expand Down Expand Up @@ -102,9 +102,9 @@ protected void onPreviewHook() {


@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme) {
float cx = x + mItemWidth / 2;
float cy = y + mItemHeight / 2;
if (isTouchDown && mCurrentItem == mItems.indexOf(getIndex())) {
//点击当前选中的item, 缩放效果提示
canvas.drawCircle(cx, cy, mRadius - dipToPx(getContext(), 4), mSelectedPaint);
Expand All @@ -115,7 +115,7 @@ protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y,
}

@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
protected void onDrawScheme(Canvas canvas, Calendar calendar, float x, float y) {

boolean isSelected = isSelected(calendar);
if (isSelected) {
Expand All @@ -129,10 +129,10 @@ protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {

@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
int top = y - mItemHeight / 6;
protected void onDrawText(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme, boolean isSelected) {
float cx = x + mItemWidth / 2;
float cy = y + mItemHeight / 2;
float top = y - mItemHeight / 6;

if (calendar.isCurrentDay() && !isSelected) {
canvas.drawCircle(cx, cy, mRadius, mCurrentDayPaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class CustomWeekView extends WeekView {


private int mRadius;
private float mRadius;

/**
* 自定义魅族标记的文本画笔
Expand Down Expand Up @@ -105,9 +105,9 @@ protected void onPreviewHook() {


@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = mItemHeight / 2;
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, float x, boolean hasScheme) {
float cx = x + mItemWidth / 2;
float cy = mItemHeight / 2;

if (isTouchDown && mCurrentItem == mItems.indexOf(getIndex())) {
//点击当前选中的item, 缩放效果提示
Expand All @@ -121,7 +121,7 @@ protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolea


@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x) {
protected void onDrawScheme(Canvas canvas, Calendar calendar, float x) {

boolean isSelected = isSelected(calendar);
if (isSelected) {
Expand All @@ -135,10 +135,10 @@ protected void onDrawScheme(Canvas canvas, Calendar calendar, int x) {

@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelected) {
int cx = x + mItemWidth / 2;
int cy = mItemHeight / 2;
int top = -mItemHeight / 6;
protected void onDrawText(Canvas canvas, Calendar calendar, float x, boolean hasScheme, boolean isSelected) {
float cx = x + mItemWidth / 2;
float cy = mItemHeight / 2;
float top = -mItemHeight / 6;

if (calendar.isCurrentDay() && !isSelected) {
canvas.drawCircle(cx, cy, mRadius, mCurrentDayPaint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CustomYearView(Context context) {
}

@Override
protected void onDrawMonth(Canvas canvas, int year, int month, int x, int y, int width, int height) {
protected void onDrawMonth(Canvas canvas, int year, int month, float x, float y, float width, float height) {

String text = getContext()
.getResources()
Expand Down Expand Up @@ -82,7 +82,7 @@ private static boolean isLeapYear(int year) {


@Override
protected void onDrawWeek(Canvas canvas, int week, int x, int y, int width, int height) {
protected void onDrawWeek(Canvas canvas, int week, float x, float y, float width, float height) {
String text = getContext().getResources().getStringArray(com.haibin.calendarview.R.array.year_view_week_string_array)[week];
canvas.drawText(text,
x + width / 2,
Expand All @@ -92,23 +92,23 @@ protected void onDrawWeek(Canvas canvas, int week, int x, int y, int width, int


@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
int radius = Math.min(mItemWidth, mItemHeight) / 8 * 5;
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme) {
float cx = x + mItemWidth / 2;
float cy = y + mItemHeight / 2;
float radius = Math.min(mItemWidth, mItemHeight) / 8 * 5;
canvas.drawCircle(cx, cy, radius, mSelectedPaint);
return true;
}

@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
protected void onDrawScheme(Canvas canvas, Calendar calendar, float x, float y) {

}

@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
protected void onDrawText(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme, boolean isSelected) {
float baselineY = mTextBaseLine + y;
int cx = x + mItemWidth / 2;
float cx = x + mItemWidth / 2;

if (isSelected) {
canvas.drawText(String.valueOf(calendar.getDay()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public FullMonthView(Context context) {
mSelectedPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.SOLID));
}

@Override
protected void drawCalendar(Canvas canvas, Calendar calendar, float x, float y, boolean isSelected) {
canvas.drawRect(x, y, x + mItemWidth, y + mItemHeight, mRectPaint);
super.drawCalendar(canvas, calendar, x, y, isSelected);
}

/**
* 绘制选中的日子
*
Expand All @@ -54,8 +60,8 @@ public FullMonthView(Context context) {
* @return true 则绘制onDrawScheme,因为这里背景色不是是互斥的
*/
@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
canvas.drawRect(x, y , x + mItemWidth, y + mItemHeight, mSelectedPaint);
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme) {
canvas.drawRect(x, y, x + mItemWidth, y + mItemHeight, mSelectedPaint);
return true;
}

Expand All @@ -69,24 +75,29 @@ protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y,
*/
@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
protected void onDrawScheme(Canvas canvas, Calendar calendar, float x, float y) {
mSchemeBasicPaint.setColor(calendar.getSchemeColor());
List<Calendar.Scheme> schemes = calendar.getSchemes();
if (schemes == null || schemes.size() == 0) {
return;
}
int space = dipToPx(getContext(), 2);
int indexY = y + mItemHeight - 2 * space;
float indexY = y + mItemHeight - 2 * space;
int sw = dipToPx(getContext(), mItemWidth / 10);
int sh = dipToPx(getContext(), 4);
//for (Calendar.Scheme scheme : schemes) {
//
// mSchemePaint.setColor(scheme.getShcemeColor());
//
// canvas.drawRect(x + mItemWidth - sw - 2 * space,
//
// indexY - sh, x + mItemWidth - 2 * space, indexY, mSchemePaint);
// indexY = indexY - space -sh;
//}
for (Calendar.Scheme scheme : schemes) {

mSchemePaint.setColor(scheme.getShcemeColor());

canvas.drawRect(x + mItemWidth - sw - 2 * space,

indexY - sh, x + mItemWidth - 2 * space, indexY, mSchemePaint);
indexY = indexY - space -sh;
canvas.drawRect(x, indexY - sh, x + mItemWidth, indexY, mSchemePaint);
indexY = indexY - space - sh;
}
}

Expand All @@ -102,10 +113,9 @@ protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
*/
@SuppressWarnings("IntegerDivisionInFloatingPointContext")
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
canvas.drawRect(x, y, x + mItemWidth, y + mItemHeight, mRectPaint);
int cx = x + mItemWidth / 2;
int top = y - mItemHeight / 6;
protected void onDrawText(Canvas canvas, Calendar calendar, float x, float y, boolean hasScheme, boolean isSelected) {
float cx = x + mItemWidth / 2;
float top = y - mItemHeight / 6;

boolean isInRange = isInRange(calendar);

Expand Down
Loading