Skip to content

Commit

Permalink
月视图和周视图支持控制可滚动,新增更新当前时间API,修复平滑滚动失效bug
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Apr 26, 2018
1 parent 3fbb90a commit 88d22b2
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 11 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Android上一个优雅、高度自定义、性能高效的日历控件,完美

### Gradle
```
compile 'com.haibin:calendarview:3.2.9'
compile 'com.haibin:calendarview:3.3.0'
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.2.9</version>
<version>3.3.0</version>
<type>pom</type>
</dependency>
```
Expand Down Expand Up @@ -152,6 +152,11 @@ compile 'com.haibin:calendarview:3.2.9'
 <attr name="max_year" format="integer" /> <!--最大年份2099-->
<attr name="min_year_month" format="integer" /> <!--最小年份对应月份-->
<attr name="max_year_month" format="integer" /> <!--最大年份对应月份-->

<!--月视图是否可滚动-->
<attr name="month_view_scrollable" format="boolean" />
<!--周视图是否可滚动-->
<attr name="week_view_scrollable" format="boolean" />

<!--配置你喜欢的月视图显示模式模式-->
<attr name="month_view_show_mode">
Expand Down
9 changes: 7 additions & 2 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ This widget has obvious advantages of memory and efficiency, adapt to many scene

### Gradle
```
compile 'com.haibin:calendarview:3.2.9'
compile 'com.haibin:calendarview:3.3.0'
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.2.9</version>
<version>3.3.0</version>
<type>pom</type>
</dependency>
```
Expand Down Expand Up @@ -149,6 +149,11 @@ compile 'com.haibin:calendarview:3.2.9'
<attr name="min_year_month" format="integer" /> <!--min month of min year-->
<attr name="max_year_month" format="integer" /> <!--max month of max year-->

<!--month_view_scrollable-->
<attr name="month_view_scrollable" format="boolean" />
<!--week_view_scrollable-->
<attr name="week_view_scrollable" format="boolean" />

<!--month_view_show_mode-->
<attr name="month_view_show_mode">
<enum name="mode_all" value="0" /> <!--show all month-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public void onClick(View v) {
findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//mCalendarView.scrollToCurrent();
mCalendarView.updateCurrentDate();
mCalendarView.scrollToCurrent();
}
});

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:background="#fff"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:current_day_lunar_text_color="#ff0000"
app:current_day_text_color="#ff0000"
app:current_month_lunar_text_color="#CFCFCF"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/activity_meizu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
app:week_background="#fff"
app:week_text_color="#111111"
app:week_start_with="sat"
app:month_view_scrollable="false"
app:week_view_scrollable="true"
app:year_view_day_text_color="#333333"
app:year_view_day_text_size="9sp"
app:year_view_month_text_color="#ff0000"
Expand Down
4 changes: 2 additions & 2 deletions calendarview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
minSdkVersion 15
//noinspection OldTargetApi
targetSdkVersion 23
versionCode 329
versionName "3.2.9"
versionCode 330
versionName "3.3.0"

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ final class CustomCalendarViewDelegate {
*/
private Calendar mCurrentDate;


private boolean mMonthViewScrollable,
mWeekViewScrollable;

/**
* 当前月份和周视图的item位置
*/
Expand Down Expand Up @@ -252,6 +256,9 @@ final class CustomCalendarViewDelegate {
mSchemeText = "记";
}

mMonthViewScrollable = array.getBoolean(R.styleable.CalendarView_month_view_scrollable, true);
mWeekViewScrollable = array.getBoolean(R.styleable.CalendarView_week_view_scrollable, true);

mMonthViewShowMode = array.getInt(R.styleable.CalendarView_month_view_show_mode, MODE_ALL_MONTH);
mWeekStart = array.getInt(R.styleable.CalendarView_week_start_with, WEEK_START_WITH_SUN);
//mSelectMode = array.getInt(R.styleable.CalendarView_select_mode, SELECT_MODE_DEFAULT);
Expand Down Expand Up @@ -494,6 +501,14 @@ void setThemeColor(int selectedThemeColor, int schemeColor) {
this.mSchemeThemeColor = schemeColor;
}

boolean isMonthViewScrollable() {
return mMonthViewScrollable;
}

boolean isWeekViewScrollable() {
return mWeekViewScrollable;
}

int getWeekStart() {
return mWeekStart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package com.haibin.calendarview;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -310,6 +312,18 @@ void updateCurrentDate() {
}
}


@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent ev) {
return mDelegate.isMonthViewScrollable() && super.onTouchEvent(ev);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return mDelegate.isMonthViewScrollable() && super.onInterceptTouchEvent(ev);
}

@Override
public void setCurrentItem(int item) {
setCurrentItem(item, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package com.haibin.calendarview;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -191,6 +193,18 @@ void updateCurrentDate() {
}



@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent ev) {
return mDelegate.isWeekViewScrollable() && super.onTouchEvent(ev);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return mDelegate.isWeekViewScrollable() && super.onInterceptTouchEvent(ev);
}

/**
* 周视图的高度应该与日历项的高度一致
*/
Expand Down
4 changes: 4 additions & 0 deletions calendarview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
<attr name="min_year_month" format="integer" />
<attr name="max_year_month" format="integer" />

<!--月视图是否可滚动-->
<attr name="month_view_scrollable" format="boolean" />
<!--周视图是否可滚动-->
<attr name="week_view_scrollable" format="boolean" />

<!-- 月份显示模式 -->
<attr name="month_view_show_mode">
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ org.gradle.jvmargs=-Xmx1536m
POM_BINTRAY_NAME=com.haibin:calendarview
POM_DESCRIPTION=A very good CalendarView for Android.
POM_ARTIFACT_ID=calendarview
VERSION_NAME=3.2.9
VERSION_CODE=3.2.9
VERSION_NAME=3.3.0
VERSION_CODE=3.3.0
POM_BINTRAY_PRPO=maven
POM_PACKAGING=aar
POM_NAME=calendarview
Expand Down

0 comments on commit 88d22b2

Please sign in to comment.