Skip to content

Commit

Permalink
3.0.2版本开源、修复周视图小bug,新增自定义周栏功能,代码整理,官方规范化
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Dec 1, 2017
1 parent 474367e commit 37833f2
Show file tree
Hide file tree
Showing 24 changed files with 890 additions and 882 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ Android上一个优雅、高度自定义、性能高效的日历控件,完美

### Gradle
```
compile 'com.haibin:calendarview:3.0.1'
compile 'com.haibin:calendarview:3.0.2'
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.0.1</version>
<version>3.0.2</version>
<type>pom</type>
</dependency>
```
### 如果你需要完全定制UI,参考demo,简单几步即可绘制你需要的效果,一般只需要实现三个回调函数绘制你需要的特效即可,自定义日历UI需要同时自定义周视图,真正做到热插拔效果,方便大众定制UI需求

### 效果预览
### 收缩展开的魅族风格效果
<img src="https://gitee.com/huanghaibin_dev/CalendarView/raw/master/app/src/main/assets/meizu.jpeg" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://gitee.com/huanghaibin_dev/CalendarView/raw/master/app/src/main/assets/shrink.jpeg" height="650"/>
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/meizu.jpeg" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/shrink.jpeg" height="650"/>
### 下标和多彩风格
<img src="https://gitee.com/huanghaibin_dev/CalendarView/raw/master/app/src/main/assets/index.jpeg" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://gitee.com/huanghaibin_dev/CalendarView/raw/master/app/src/main/assets/colorful.jpeg" height="650"/>
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/index.jpeg" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/colorful.jpeg" height="650"/>
### 快速年份月份切换
<img src="https://gitee.com/huanghaibin_dev/CalendarView/raw/master/app/src/main/assets/month.jpeg" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://gitee.com/huanghaibin_dev/CalendarView/raw/master/app/src/main/assets/simple.jpeg" height="650"/>
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/month.jpeg" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/simple.jpeg" height="650"/>


### 使用方法
Expand All @@ -40,6 +40,7 @@ compile 'com.haibin:calendarview:3.0.1'
android:background="#fff"
app:calendar_card_view="com.haibin.calendarviewproject.simple.SimpleCalendarCardView"
app:week_view="com.haibin.calendarviewproject.simple.SimpleWeekView"
app:week_bar_view="com.haibin.calendarviewproject.EnglishWeekBar"
app:calendar_height="50dp"
app:current_month_text_color="#333333"
app:current_month_lunar_text_color="#CFCFCF"
Expand Down Expand Up @@ -67,6 +68,7 @@ compile 'com.haibin:calendarview:3.0.1'

<attr name="calendar_card_view" format="color" /> <!--热插拔自定义类日历月视图路径-->
<attr name="week_view" format="color" /> <!--热插拔自定义类周视图路径-->
<attr name="week_bar_view" format="color" /> <!--自定义类周栏路径-->

<attr name="week_background" format="color" /> <!--星期栏的背景-->
<attr name="week_text_color" format="color" /> <!--星期栏文本颜色-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.haibin.calendarviewproject;

import android.content.Context;
import android.view.LayoutInflater;

import com.haibin.calendarview.WeekBar;

/**
* 自定义英文栏
* Created by huanghaibin on 2017/11/30.
*/

public class EnglishWeekBar extends WeekBar {
public EnglishWeekBar(Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.english_week_bar, this, true);
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
android:textColor="#000000"
android:textSize="12sp" />
</FrameLayout>

</RelativeLayout>

<com.haibin.calendarview.CalendarLayout
Expand All @@ -102,7 +103,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
app:calendar_card_view="com.haibin.calendarviewproject.meizu.MeiZuCalendarCardView"
app:current_month_lunar_text_color="#CFCFCF"
app:current_month_text_color="#333333"
app:lunar_text_size="10sp"
Expand All @@ -116,8 +116,8 @@
app:selected_text_color="#333"
app:selected_theme_color="#108cd4"
app:week_background="#fff"
app:week_text_color="#111"
app:week_view="com.haibin.calendarviewproject.meizu.MeizuWeekView" />
app:week_bar_view="com.haibin.calendarviewproject.EnglishWeekBar"
app:week_text_color="#111" />

<LinearLayout
android:id="@+id/linearView"
Expand Down
82 changes: 82 additions & 0 deletions app/src/main/res/layout/english_week_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_week"
android:layout_width="match_parent"
android:layout_height="40dp"
android:minHeight="40dp"
android:orientation="horizontal"
android:paddingBottom="8dp"
android:paddingTop="8dp"
tools:ignore="HardcodedText">

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Sun"
android:textColor="#A3A3A3"
android:textSize="12sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:textColor="#A3A3A3"
android:text="Mon"
android:textSize="12sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Tue"
android:textColor="#A3A3A3"
android:textSize="12sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Wed"
android:textColor="#A3A3A3"
android:textSize="12sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="Thu"
android:textColor="#A3A3A3"
android:textSize="12sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:textColor="#A3A3A3"
android:text="Fri"
android:textSize="12sp"
android:textStyle="bold" />

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:textColor="#A3A3A3"
android:text="Sat"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
7 changes: 5 additions & 2 deletions calendarview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ android {

defaultConfig {
minSdkVersion 15
//noinspection OldTargetApi
targetSdkVersion 23
versionCode 301
versionName "3.0.1"
versionCode 302
versionName "3.0.2"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -39,7 +40,9 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//noinspection GradleDependency
compile 'com.android.support:appcompat-v7:23.3.0'
//noinspection GradleDependency
compile 'com.android.support:recyclerview-v7:23.3.0'
testCompile 'junit:junit:4.12'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.view.View;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
Expand All @@ -36,6 +35,7 @@

public abstract class BaseCalendarCardView extends View implements View.OnClickListener {

private CustomCalendarViewDelegate mDelegate;
/**
* 当前月份日期的笔
*/
Expand Down Expand Up @@ -76,26 +76,6 @@ public abstract class BaseCalendarCardView extends View implements View.OnClickL
*/
protected Paint mSelectedPaint = new Paint();

/**
* 日期被选中监听
*/
CalendarView.OnDateSelectedListener mDateSelectedListener;

/**
* 内部日期切换监听,用于内部更新计算
*/
CalendarView.OnInnerDateSelectedListener mInnerListener;

/**
* 日期切换监听
*/
CalendarView.OnDateChangeListener mListener;

/**
* 当前日历
*/
Calendar mCurrent;

/**
* 当前日历卡年份
*/
Expand Down Expand Up @@ -267,7 +247,8 @@ private void initPaint(Context context) {
setOnClickListener(this);
}

void setup(CalendarView.CalendarViewDelegate delegate) {
void setup(CustomCalendarViewDelegate delegate) {
this.mDelegate = delegate;
mCurMonthTextColor = delegate.getCurrentMonthTextColor();
mCurMonthLunarTextColor = delegate.getCurrentMonthLunarTextColor();
mCurDayTextPaint.setColor(delegate.getCurDayTextColor());
Expand Down Expand Up @@ -389,24 +370,24 @@ public void onClick(View v) {
mParentLayout.mViewPager.setCurrentItem(position);
}

if (mInnerListener != null) {
mInnerListener.onDateSelected(calendar);
if (mDelegate.mInnerListener != null) {
mDelegate.mInnerListener.onDateSelected(calendar);
}

if (mParentLayout != null ) {
if(calendar.isCurrentMonth()){
if (mParentLayout != null) {
if (calendar.isCurrentMonth()) {
mParentLayout.setSelectPosition(mItems.indexOf(calendar));
}else {
} else {
mParentLayout.setSelectWeek(Util.getWeekFromDayInMonth(calendar));
}

}

if (mDateSelectedListener != null) {
mDateSelectedListener.onDateSelected(calendar);
if (mDelegate.mDateSelectedListener != null) {
mDelegate.mDateSelectedListener.onDateSelected(calendar);
}
if (mListener != null) {
mListener.onDateChange(calendar);
if (mDelegate.mDateChangeListener != null) {
mDelegate.mDateChangeListener.onDateChange(calendar);
}
invalidate();
}
Expand Down Expand Up @@ -445,11 +426,6 @@ void setSelectedCalendar(Calendar calendar) {
void setCurrentDate(int year, int month) {
mYear = year;
mMonth = month;
mCurrent = new Calendar();
Date d = new Date();
mCurrent.setYear(Util.getDate("yyyy", d));
mCurrent.setMonth(Util.getDate("MM", d));
mCurrent.setDay(Util.getDate("dd", d));
initCalendar();
}

Expand Down Expand Up @@ -514,7 +490,7 @@ private void initCalendar() {
calendarDate.setCurrentMonth(true);
calendarDate.setDay(i - firstDayOfWeek + 1);
}
if (calendarDate.equals(mCurrent)) {
if (calendarDate.equals(mDelegate.getCurrentDay())) {
calendarDate.setCurrentDay(true);
mCurrentItem = i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CalendarLayout extends LinearLayout {
/**
* 自定义ViewPager
*/
WrapViewPager mViewPager;
MonthViewPager mViewPager;

WeekViewPager mWeekPager;
/**
Expand Down Expand Up @@ -136,7 +136,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mViewPager = (WrapViewPager) findViewById(R.id.vp_calendar).findViewById(R.id.vp_calendar);
mViewPager = (MonthViewPager) findViewById(R.id.vp_calendar).findViewById(R.id.vp_calendar);
mWeekPager = (WeekViewPager) findViewById(R.id.vp_week).findViewById(R.id.vp_week);
mContentView = (ViewGroup) findViewById(mContentViewId);
if (mContentView != null) {
Expand Down
Loading

0 comments on commit 37833f2

Please sign in to comment.