|
@@ -4,8 +4,12 @@ import android.content.Context;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.Paint;
|
|
|
+import android.graphics.Rect;
|
|
|
+import android.graphics.RectF;
|
|
|
import android.view.View;
|
|
|
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
+import com.cooleshow.teacher.R;
|
|
|
import com.haibin.calendarview.Calendar;
|
|
|
import com.haibin.calendarview.MonthView;
|
|
|
|
|
@@ -19,6 +23,13 @@ public class SimpleMonthView extends MonthView {
|
|
|
private int mRadius;
|
|
|
// private Paint mPaint = new Paint();
|
|
|
Context context;
|
|
|
+ private int maxSelectBgWidth;
|
|
|
+ private int spaceMarginBottom;
|
|
|
+ private int spaceMarginTop;
|
|
|
+ private int schemeTextSize;
|
|
|
+ private int schemeTextColor;
|
|
|
+ private int schemeTextColorSelect;
|
|
|
+ private Paint schemeBgPaint = new Paint();
|
|
|
|
|
|
public SimpleMonthView(Context context) {
|
|
|
super(context);
|
|
@@ -26,6 +37,16 @@ public class SimpleMonthView extends MonthView {
|
|
|
//兼容硬件加速无效的代码
|
|
|
setLayerType(View.LAYER_TYPE_SOFTWARE, mSelectedPaint);
|
|
|
setBackgroundColor(Color.WHITE);
|
|
|
+ maxSelectBgWidth = SizeUtils.dp2px(32);
|
|
|
+ mRadius = SizeUtils.dp2px(2);
|
|
|
+ spaceMarginBottom = SizeUtils.dp2px(5);
|
|
|
+ spaceMarginTop = SizeUtils.dp2px(10);
|
|
|
+ schemeTextSize = SizeUtils.sp2px(10);
|
|
|
+ schemeTextColor = context.getResources().getColor(com.cooleshow.base.R.color.color_ff6363);
|
|
|
+ schemeTextColorSelect = context.getResources().getColor(R.color.white);
|
|
|
+ schemeBgPaint.setColor(context.getResources().getColor(com.cooleshow.base.R.color.color_30ffd7a6));
|
|
|
+ schemeBgPaint.setAntiAlias(true);
|
|
|
+ schemeBgPaint.setStyle(Paint.Style.FILL);
|
|
|
//4.0以上硬件加速会导致无效
|
|
|
// mSelectedPaint.setMaskFilter(new BlurMaskFilter(25, BlurMaskFilter.Blur.SOLID));
|
|
|
//
|
|
@@ -38,7 +59,8 @@ public class SimpleMonthView extends MonthView {
|
|
|
|
|
|
@Override
|
|
|
protected void onPreviewHook() {
|
|
|
- mRadius = Math.min(mItemWidth, mItemHeight) / 2;
|
|
|
+// mRadius = Math.min(mItemWidth, mItemHeight) / 2;
|
|
|
+ mRadius = SizeUtils.dp2px(2);
|
|
|
mSchemePaint.setStyle(Paint.Style.STROKE);
|
|
|
}
|
|
|
|
|
@@ -59,12 +81,20 @@ public class SimpleMonthView extends MonthView {
|
|
|
*/
|
|
|
@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);
|
|
|
+ RectF rect = buildRect(x, y);
|
|
|
+ canvas.drawRoundRect(rect, mRadius, mRadius, mSelectedPaint);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private RectF buildRect(int x, int y) {
|
|
|
+ RectF rect = new RectF();
|
|
|
+ rect.left = x + Math.abs(mItemWidth - maxSelectBgWidth) / 2;
|
|
|
+ rect.right = x + mItemWidth - Math.abs(mItemWidth - maxSelectBgWidth) / 2;
|
|
|
+ rect.top = y + spaceMarginTop;
|
|
|
+ rect.bottom = y + mItemHeight;
|
|
|
+ return rect;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 绘制标记的事件日子
|
|
|
*
|
|
@@ -76,9 +106,8 @@ public class SimpleMonthView extends MonthView {
|
|
|
|
|
|
@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);
|
|
|
+ RectF rect = buildRect(x, y);
|
|
|
+ canvas.drawRoundRect(rect, mRadius, mRadius, schemeBgPaint);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -103,23 +132,24 @@ public class SimpleMonthView extends MonthView {
|
|
|
cx,
|
|
|
baselineY,
|
|
|
mSelectTextPaint);
|
|
|
+ if (hasScheme) {
|
|
|
+ mSchemeTextPaint.setTextSize(schemeTextSize);
|
|
|
+ mSchemeTextPaint.setColor(schemeTextColorSelect);
|
|
|
+ canvas.drawText("有课", cx, y + mItemHeight - spaceMarginBottom, mSchemeTextPaint);
|
|
|
+ }
|
|
|
} else if (hasScheme) {//否则绘制具有标记的
|
|
|
canvas.drawText(calendar.isCurrentDay() ? "今" : String.valueOf(calendar.getDay()),
|
|
|
cx,
|
|
|
baselineY,
|
|
|
- calendar.isCurrentDay() ? mCurDayTextPaint :
|
|
|
- calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
|
|
|
-// if (calendar.isCurrentDay()) {
|
|
|
-// canvas.drawCircle(cx, cy, mRadius- dipToPx(context, 1), mPaint);
|
|
|
-// }
|
|
|
+ getPaint(calendar));
|
|
|
+ mSchemeTextPaint.setTextSize(schemeTextSize);
|
|
|
+ mSchemeTextPaint.setColor(schemeTextColor);
|
|
|
+ canvas.drawText("有课", cx, y + mItemHeight - spaceMarginBottom, mSchemeTextPaint);
|
|
|
} else {//最好绘制普通文本
|
|
|
canvas.drawText(calendar.isCurrentDay() ? "今" : String.valueOf(calendar.getDay()), cx, baselineY,
|
|
|
getPaint(calendar));
|
|
|
-// if (calendar.isCurrentDay()) {
|
|
|
-// canvas.drawCircle(cx, cy, mRadius- dipToPx(context, 1), mPaint);
|
|
|
-// }
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private Paint getPaint(Calendar calendar) {
|
|
@@ -130,7 +160,6 @@ public class SimpleMonthView extends MonthView {
|
|
|
if (calendar.isWeekend()) {
|
|
|
return mCurDayTextPaint;
|
|
|
}
|
|
|
-
|
|
|
if (calendar.isCurrentMonth()) {
|
|
|
return mCurMonthTextPaint;
|
|
|
}
|