Skip to content

Commit

Permalink
调整自定义Painter
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Jul 5, 2019
1 parent 309f1d2 commit cd965f1
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 250 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file added app/month.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 60 additions & 36 deletions app/src/main/java/com/necer/ncalendar/CustomPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import com.necer.painter.CalendarPainter;
import com.necer.utils.Util;

import org.joda.time.LocalDate;

import java.util.List;

/**
* Created by necer on 2019/1/3.
*/
Expand All @@ -27,58 +31,78 @@ public CustomPainter(Context context) {
}


@Override
public void onDrawToday(Canvas canvas, Rect rect, NDate nDate,boolean is) {
// @Override
// public void onDrawToday(Canvas canvas, Rect rect, NDate nDate,boolean is) {
//
// if (false) {
// paint.setColor(Color.RED);
// canvas.drawRect(getNewRect(context,rect), paint);
// paint.setColor(Color.WHITE);
// } else {
// paint.setColor(Color.LTGRAY);
// canvas.drawRect(getNewRect(context,rect), paint);
// paint.setColor(Color.GREEN);
// }
// canvas.drawText(nDate.localDate.getDayOfMonth() + "", rect.centerX(), getBaseLineY(rect), paint);
//
//
// }
//
// @Override
// public void onDrawDisableDate(Canvas canvas, Rect rect, NDate nDate) {
//
// }
//
// @Override
// public void onDrawCurrentMonthOrWeek(Canvas canvas, Rect rect, NDate nDate, boolean isSelect) {
// if (isSelect) {
// paint.setColor(Color.BLACK);
// canvas.drawRect(getNewRect(context,rect), paint);
// paint.setColor(Color.WHITE);
// } else {
// paint.setColor(Color.BLACK);
// }
// canvas.drawText(nDate.localDate.getDayOfMonth() + "", rect.centerX(), getBaseLineY(rect), paint);
//
// }
//
// @Override
// public void onDrawNotCurrentMonth(Canvas canvas, Rect rect, NDate nDate,boolean isSelect) {
// paint.setColor(Color.LTGRAY);
// canvas.drawText(nDate.localDate.getDayOfMonth() + "", rect.centerX(), getBaseLineY(rect), paint);
// }

if (false) {
paint.setColor(Color.RED);
canvas.drawRect(getNewRect(context,rect), paint);
paint.setColor(Color.WHITE);
} else {
paint.setColor(Color.LTGRAY);
canvas.drawRect(getNewRect(context,rect), paint);
paint.setColor(Color.GREEN);
}
canvas.drawText(nDate.localDate.getDayOfMonth() + "", rect.centerX(), getBaseLineY(rect), paint);

private int getBaseLineY(Rect rect) {
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
float top = fontMetrics.top;
float bottom = fontMetrics.bottom;
int baseLineY = (int) (rect.centerY() - top / 2 - bottom / 2);
return baseLineY;
}

private Rect getNewRect(Context context,Rect rect) {
int rectDistance = (int) Util.dp2px(context, 20);
return new Rect(rect.centerX() - rectDistance, rect.centerY() - rectDistance, rect.centerX() + rectDistance, rect.centerY() + rectDistance);
}

@Override
public void onDrawDisableDate(Canvas canvas, Rect rect, NDate nDate) {
public void onDrawToday(Canvas canvas, Rect rect, LocalDate localDate, List<LocalDate> selectedDateList) {

}

@Override
public void onDrawCurrentMonthOrWeek(Canvas canvas, Rect rect, NDate nDate, boolean isSelect) {
if (isSelect) {
paint.setColor(Color.BLACK);
canvas.drawRect(getNewRect(context,rect), paint);
paint.setColor(Color.WHITE);
} else {
paint.setColor(Color.BLACK);
}
canvas.drawText(nDate.localDate.getDayOfMonth() + "", rect.centerX(), getBaseLineY(rect), paint);
public void onDrawCurrentMonthOrWeek(Canvas canvas, Rect rect, LocalDate localDate, List<LocalDate> selectedDateList) {

}

@Override
public void onDrawNotCurrentMonth(Canvas canvas, Rect rect, NDate nDate,boolean isSelect) {
paint.setColor(Color.LTGRAY);
canvas.drawText(nDate.localDate.getDayOfMonth() + "", rect.centerX(), getBaseLineY(rect), paint);
}

public void onDrawLastOrNextMonth(Canvas canvas, Rect rect, LocalDate localDate, List<LocalDate> selectedDateList) {

private int getBaseLineY(Rect rect) {
Paint.FontMetrics fontMetrics = paint.getFontMetrics();
float top = fontMetrics.top;
float bottom = fontMetrics.bottom;
int baseLineY = (int) (rect.centerY() - top / 2 - bottom / 2);
return baseLineY;
}

private Rect getNewRect(Context context,Rect rect) {
int rectDistance = (int) Util.dp2px(context, 20);
return new Rect(rect.centerX() - rectDistance, rect.centerY() - rectDistance, rect.centerX() + rectDistance, rect.centerY() + rectDistance);
@Override
public void onDrawDisableDate(Canvas canvas, Rect rect, LocalDate localDate) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
innerPainter.setReplaceLunarStrMap(strMap);

Map<String, Integer> colorMap = new HashMap<>();
colorMap.put("2019-01-25", Color.RED);
colorMap.put("2019-07-25", Color.RED);

colorMap.put("2019-01-24", Color.parseColor("#000000"));
colorMap.put("2019-07-5", Color.parseColor("#000000"));
innerPainter.setReplaceLunarColorMap(colorMap);


Expand Down
Binary file added app/week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 0 additions & 17 deletions ncalendar/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'com.android.library'

apply plugin: 'com.novoda.bintray-release'


Expand All @@ -10,27 +9,11 @@ android {
targetSdkVersion 27
versionCode 1
versionName "4.0.4"

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

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
api 'joda-time:joda-time:2.10.1'
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.necer.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.necer.utils.Util;
import com.necer.view.CalendarView;
import com.necer.view.WeekView;

import org.joda.time.LocalDate;

import java.util.List;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ public interface CalendarPainter {


//绘制今天的日期
void onDrawToday(Canvas canvas, Rect rect, NDate nDate, boolean isSelect);
void onDrawToday(Canvas canvas, Rect rect, LocalDate localDate, List<LocalDate> selectedDateList);

//绘制当前月或周的日期
void onDrawCurrentMonthOrWeek(Canvas canvas, Rect rect, NDate nDate, boolean isSelect);
void onDrawCurrentMonthOrWeek(Canvas canvas, Rect rect, LocalDate localDate, List<LocalDate> selectedDateList);

//绘制上一月,下一月的日期,周日历不须实现
void onDrawNotCurrentMonth(Canvas canvas, Rect rect, NDate nDate, boolean isSelect);
void onDrawLastOrNextMonth(Canvas canvas, Rect rect, LocalDate localDate, List<LocalDate> selectedDateList);

//绘制不可用的日期,和方法setDateInterval(startFormatDate, endFormatDate)对应
void onDrawDisableDate(Canvas canvas, Rect rect, NDate nDate);
void onDrawDisableDate(Canvas canvas, Rect rect, LocalDate localDate);


}
Loading

0 comments on commit cd965f1

Please sign in to comment.