Skip to content

Commit

Permalink
new version and fix full style
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Mar 27, 2019
1 parent 8bafc32 commit 67bbee1
Show file tree
Hide file tree
Showing 17 changed files with 706 additions and 126 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ You can't think of the calendar can be so elegant!

### Gradle
```
compile 'com.haibin:calendarview:3.5.5'
compile 'com.haibin:calendarview:3.5.7'
```

```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.5.5</version>
<version>3.5.7</version>
<type>pom</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Android上一个优雅、高度自定义、性能高效的日历控件,完美

### Gradle
```
compile 'com.haibin:calendarview:3.5.5'
compile 'com.haibin:calendarview:3.5.7'
```
```
<dependency>
<groupId>com.haibin</groupId>
<artifactId>calendarview</artifactId>
<version>3.5.5</version>
<version>3.5.7</version>
<type>pom</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ dependencies {
//noinspection GradleDependency
compile 'com.github.bumptech.glide:glide:3.7.0'
testCompile 'junit:junit:4.12'
//compile 'com.haibin:calendarview:3.5.6'
compile project(':calendarview')
compile 'com.haibin:calendarview:3.5.7'
//compile project(':calendarview')
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ protected void initView() {

mRelativeTool = (RelativeLayout) findViewById(R.id.rl_tool);
mCalendarView = (CalendarView) findViewById(R.id.calendarView);
//mCalendarView.setRange(2018, 7, 1, 2019, 4, 28);
mTextCurrentDay = (TextView) findViewById(R.id.tv_current_day);
mTextMonthDay.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -128,7 +129,7 @@ public void onClick(DialogInterface dialog, int which) {
mCalendarView.scrollToCalendar(2018,12,30);
break;
case 5:
mCalendarView.setRange(2016, 7, 1, 2016, 9, 28);
mCalendarView.setRange(2018, 7, 1, 2019, 4, 28);
// mCalendarView.setRange(mCalendarView.getCurYear(), mCalendarView.getCurMonth(), 6,
// mCalendarView.getCurYear(), mCalendarView.getCurMonth(), 23);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ public FullMonthView(Context context) {
mSelectedPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.SOLID));
}

@Override
public void invalidate() {
super.invalidate();
Log.e("invalidate","invalidate");
}

@Override
protected void onPreviewHook() {
super.onPreviewHook();
Log.e("onPreviewHook"," -- " + getHeight());
}

/**
* 绘制选中的日子
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,21 @@
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.WeekView;

import java.util.List;

/**
* 魅族周视图
* Created by huanghaibin on 2017/11/29.
*/

public class FullWeekView extends WeekView {
private Paint mTextPaint = new Paint();
private Paint mRectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private Paint mSchemeBasicPaint = new Paint();
private float mRadio;
private int mPadding;
private float mSchemeBaseLine;


public FullWeekView(Context context) {
super(context);

mTextPaint.setTextSize(dipToPx(context, 8));
mTextPaint.setColor(0xffffffff);
mTextPaint.setAntiAlias(true);
mTextPaint.setFakeBoldText(true);

mRectPaint.setStyle(Paint.Style.STROKE);
mRectPaint.setStrokeWidth(dipToPx(context, 0.5f));
mRectPaint.setColor(0x88efefef);
Expand All @@ -39,15 +33,11 @@ public FullWeekView(Context context) {
mSchemeBasicPaint.setTextAlign(Paint.Align.CENTER);
mSchemeBasicPaint.setColor(0xffed5353);
mSchemeBasicPaint.setFakeBoldText(true);
mRadio = dipToPx(getContext(), 7);
mPadding = dipToPx(getContext(), 4);
Paint.FontMetrics metrics = mSchemeBasicPaint.getFontMetrics();
mSchemeBaseLine = mRadio - metrics.descent + (metrics.bottom - metrics.top) / 2 + dipToPx(getContext(), 1);

//兼容硬件加速无效的代码
setLayerType(View.LAYER_TYPE_SOFTWARE, mSchemeBasicPaint);
//4.0以上硬件加速会导致无效
mSchemeBasicPaint.setMaskFilter(new BlurMaskFilter(25, BlurMaskFilter.Blur.SOLID));
mSelectedPaint.setMaskFilter(new BlurMaskFilter(50, BlurMaskFilter.Blur.SOLID));
}

/**
Expand All @@ -67,23 +57,31 @@ protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolea
@Override
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x) {
mSchemeBasicPaint.setColor(calendar.getSchemeColor());
List<Calendar.Scheme> schemes = calendar.getSchemes();
if (schemes == null || schemes.size() == 0) {
return;
}
int space = dipToPx(getContext(), 2);
int indexY = mItemHeight - 2 * space;
int sw = dipToPx(getContext(), mItemWidth / 10);
int sh = dipToPx(getContext(), 4);
for (Calendar.Scheme scheme : schemes) {

canvas.drawCircle(x + mItemWidth - mPadding - mRadio / 2, mPadding + mRadio, mRadio, mSchemeBasicPaint);
mSchemePaint.setColor(scheme.getShcemeColor());

canvas.drawText(calendar.getScheme(),
x + mItemWidth - mPadding - mRadio / 2 - getTextWidth(calendar.getScheme()) / 2,
mPadding + mSchemeBaseLine, mTextPaint);
}
canvas.drawRect(x + mItemWidth - sw - 2 * space,

private float getTextWidth(String text) {
return mTextPaint.measureText(text);
indexY - sh, x + mItemWidth - 2 * space, indexY, mSchemePaint);
indexY = indexY - space -sh;
}
}


@Override
protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelected) {
canvas.drawRect(x, 0, x + mItemWidth, mItemHeight, mRectPaint);
canvas.drawRect(x, 0, x + mItemWidth, mItemHeight, mRectPaint);
int cx = x + mItemWidth / 2;
int top = -mItemHeight / 6;
int top = - mItemHeight / 6;

boolean isInRange = isInRange(calendar);

Expand All @@ -95,12 +93,12 @@ protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasSc
canvas.drawText(String.valueOf(calendar.getDay()), cx, mTextBaseLine + top,
calendar.isCurrentMonth() && isInRange ? mSchemeTextPaint : mOtherMonthTextPaint);

canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + mItemHeight / 10, mCurMonthLunarTextPaint);
canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + mItemHeight / 10, mCurMonthLunarTextPaint);
} else {
canvas.drawText(String.valueOf(calendar.getDay()), cx, mTextBaseLine + top,
calendar.isCurrentDay() && isInRange ? mCurDayTextPaint :
calendar.isCurrentDay() ? mCurDayTextPaint :
calendar.isCurrentMonth() && isInRange ? mCurMonthTextPaint : mOtherMonthTextPaint);
canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + mItemHeight / 10,
canvas.drawText(calendar.getLunar(), cx, mTextBaseLine + mItemHeight / 10,
calendar.isCurrentDay() && isInRange ? mCurDayLunarTextPaint :
calendar.isCurrentMonth() ? mCurMonthLunarTextPaint : mOtherMonthLunarTextPaint);
}
Expand Down
Loading

0 comments on commit 67bbee1

Please sign in to comment.