# CalendarView
**Repository Path**: deciche/CalendarView
## Basic Information
- **Project Name**: CalendarView
- **Description**: Android上一个优雅、万能自定义UI、支持周视图、自定义周起始、性能高效的日历控件,支持热插拔实现的UI定制!支持标记、自定义颜色、农历、自定义月视图各种显示模式等。Canvas绘制,速度快、占用内存低,你真的想不到日历居然还可以如此优雅!An elegant, highly customized and high-performance Calendar Widget on Android.
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2018-09-11
- **Last Updated**: 2021-09-04
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# CalenderView
An elegant, highly customized and high-performance Calendar Widget on Android is perfect for supporting WeekView, supporting tags, customizing colors, lunar calendar, etc., and multi-functional MonthView display. Canvas draw is fast, low in memory and simple in customization. It can achieve any custom layout and custom UI, and support shrink expansion. The performance is very efficient.
This widget has obvious advantages of memory and efficiency, adapt to many scenes, and support multi colored calendar business. You really can't imagine that calendars can be so elegant. Please see more reference usage Demo, Demo achieved 4 exquisite custom effects.
### Gradle
```
compile 'com.haibin:calendarview:3.4.3'
```
```
com.haibin
calendarview
3.4.3
pom
```
### List some of the commonly used questions to support
> * Does it support the weekend colors alone? Support, you need to customize MonthView, WeekView, using Calendar.isWeekend() API to judge whether or not to use the corresponding brush for the weekend.
> * Does it support linkage with other widget? Support, if you like the quick date skip of other widget, you can also use similar widget by invoking API CalendarView.scrollToCalendar(), scrollPre() and scrollNext() etc..
> * Does it support the length of the date? Support, long click to the callback you can do something like sound, vibration effects, this widget does not provide, is not conducive to decoupling.
> * Does it support the use of pictures as a click effect? Support, but you need to be able to use api Canvas.drawBitmap().
> * Does it support grid display? Of course, it's supported. It depends on how you draw it.
> * Does it support custom week start?Yes,You can use mon、sun、sat for CalendarView by using week_start_with attr.
> * Does it support to callback WeekBar with date select? Support, you need to customize WeekBar, Override onDateSelected(Calendar calendar,int weekStart, Boolean isClick);
> * Therefore, as long as it is UI appearing in MonthView and WeekView, like pentagram, Bessel curve, picture and so on, are all supported, as long as you can draw, Weather it is beautiful or not, it depends on you.
### proguard-rules
```java
-keepclasseswithmembers class * {
public (android.content.Context);
}
```
### or using this proguard-rules
``` java
-keep class your project path.MonthView {
public (android.content.Context);
}
-keep class your project path.WeekBar {
public (android.content.Context);
}
-keep class your project path.WeekView {
public (android.content.Context);
}
```
### If you want to use the English version, it means you don't need to use the lunar calendar, customize MonthView and WeekView, and refer to Demo.
### Effect preview
### Function List
###
###
###
###
###
###
### In particular, please replace with your custom path.
```xml
app:month_view="com.haibin.calendarviewproject.simple.SimpleCalendarCardView"
app:week_view="com.haibin.calendarviewproject.simple.SimpleWeekView"
app:week_bar_view="com.haibin.calendarviewproject.EnglishWeekBar"
```
### usage
```xml
```
### CalendarView attrs
```xml
```
### CalendarView api
```java
public void setRange(int minYear, int minYearMonth, int minYearDay,
int maxYear, int maxYearMonth, int maxYearDay) ;//date range
public int getCurDay(); //get today
public int getCurMonth(); //get currentMonth
public int getCurYear(); //get currentYear
public boolean isYearSelectLayoutVisible();//is yearViewSelectedLayout visible?
public void closeYearSelectLayout();//close yearViewSelectedLayout
public void showYearSelectLayout(final int year); //show yearViewSelectedLayout
public void setOnMonthChangeListener(OnMonthChangeListener listener);//month change listener
public void setOnYearChangeListener(OnYearChangeListener listener);//year change listener
public void setOnCalendarSelectListener(OnCalendarSelectListener listener)//date selected listener
public void setOnCalendarLongClickListener(OnCalendarLongClickListener listener);//date long click listener
public void setOnCalendarLongClickListener(OnCalendarLongClickListener listener, boolean preventLongPressedSelect);//date long click listener
public void setOnCalendarInterceptListener(OnCalendarInterceptListener listener);//Intercept calendar click and Available draw
public Calendar getMinRangeCalendar();//getMinRangeCalendar
public Calendar getMaxRangeCalendar();//getMaxRangeCalendar
/**
* mark dates
* when mSchemeDatesMap.size()>10000?,use this
* key=Calendar.toString();
* best performance
*
* @param mSchemeDates mSchemeDatesMap
*/
public void setSchemeDate(Map mSchemeDates);//mark dates
public void update();//update change
public Calendar getSelectedCalendar(); //get current selected calendar
/**
* In particular, if you need to customize or use other selectors, you can use the following methods to interact with the calendar.
*/
public void scrollToCurrent();
public void scrollToCurrent(boolean smoothScroll);
public void scrollToYear(int year);
public void scrollToYear(int year,boolean smoothScroll);
public void scrollToPre();
public void scrollToPre(boolean smoothScroll);
public void scrollToNext();
public void scrollToNext(boolean smoothScroll);
public void scrollToCalendar(int year, int month, int day);
public void scrollToCalendar(int year, int month, int day,boolean smoothScroll);
/**
* setBackground
*
* @param yearLayoutBackground yearSelectLayout
* @param weekBackground WeekBar
* @param lineBg Line
*/
public void setBackground(int yearLayoutBackground, int weekBackground, int lineBg)
/**
* setTextColor
*
* @param curMonthTextColor curMonthTextColor
* @param otherMonthColor otherMonthColor
* @param lunarTextColor lunarTextColor
*/
public void setTextColor(int curMonthTextColor,int otherMonthColor,int lunarTextColor)
/**
* setWeeColor
*
* @param weekBackground 背景色
* @param weekTextColor 字体颜色
*/
public void setWeeColor(int weekBackground, int weekTextColor)
```
### CalendarLayout api
```java
public void expand(); //expand
public void shrink(); //shrink
public boolean isExpand();//isExpand
```
### CalendarLayout attrs
```xml
```
### If you need to fully customize the UI, refer to the demo, a few steps can be done to draw the effect you need. The MonthView and WeekView need to be replaced at the same time to achieve UI consistency.
#### First draw the MonthView
```java
public class SimpleCalendarCardView extends MonthView {
private int mRadius;
public SimpleCalendarCardView(Context context) {
super(context);
}
@Override
protected void onPreviewHook() {
mRadius = Math.min(mItemWidth, mItemHeight) / 5 * 2;
mSchemePaint.setStyle(Paint.Style.STROKE);
}
@Override
protected void onLoopStart(int x, int y) {
}
@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
return false;
}
@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
int cx = x + mItemWidth / 2;
int cy = y + mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
}
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
float baselineY = mTextBaseLine + y;
int cx = x + mItemWidth / 2;
if (hasScheme) {
canvas.drawText(String.valueOf(calendar.getDay()),
cx,
baselineY,
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
} else {
canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
}
}
}
```
#### Second, draw the WeekView, the WeekView is almost the same, the only difference is that you do not need y, only one line, so you can copy the code directly, and then make y=0.
```java
public class SimpleWeekView extends WeekView{
private int mRadius;
public SimpleWeekView(Context context) {
super(context);
}
@Override
protected void onPreviewHook() {
mRadius = Math.min(mItemWidth, mItemHeight) / 5 * 2;
mSchemePaint.setStyle(Paint.Style.STROKE);
}
@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolean hasScheme) {
int cx = x + mItemWidth / 2;
int cy = mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
return false
}
@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x) {
int cx = x + mItemWidth / 2;
int cy = mItemHeight / 2;
canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
}
@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelected) {
float baselineY = mTextBaseLine ;
int cx = x + mItemWidth / 2;
if (hasScheme) {
canvas.drawText(String.valueOf(calendar.getDay()),
cx,
baselineY,
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() ? mSchemeTextPaint : mSchemeTextPaint);
} else {
canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() ? mCurMonthTextPaint : mCurMonthTextPaint);
}
}
}
```
## Licenses
- Copyright (C) 2013 huanghaibin_dev
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
limitations under the License.