Skip to content

Commit

Permalink
v3.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Feb 5, 2021
1 parent 65f747a commit 18c6202
Show file tree
Hide file tree
Showing 20 changed files with 277 additions and 84 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected void initView() {

mRelativeTool = findViewById(R.id.rl_tool);
mCalendarView = findViewById(R.id.calendarView);

//mCalendarView.setRange(2018, 7, 1, 2019, 4, 28);
mTextCurrentDay = findViewById(R.id.tv_current_day);
mTextMonthDay.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,15 @@ public CustomMonthView(Context context) {

Paint.FontMetrics metrics = mSchemeBasicPaint.getFontMetrics();
mSchemeBaseLine = mCircleRadius - metrics.descent + (metrics.bottom - metrics.top) / 2 + dipToPx(getContext(), 1);


}


@Override
protected void onPreviewHook() {
mSolarTermTextPaint.setTextSize(mCurMonthLunarTextPaint.getTextSize());
mRadius = Math.min(mItemWidth, mItemHeight) / 11 * 5;
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

@Override
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.recyclerview.widget.LinearLayoutManager;

Expand Down Expand Up @@ -64,8 +65,8 @@ protected void initView() {
mTextYear = findViewById(R.id.tv_year);
mTextLunar = findViewById(R.id.tv_lunar);
mRelativeTool = findViewById(R.id.rl_tool);
mCalendarView = findViewById(R.id.calendarView);
mTextCurrentDay = findViewById(R.id.tv_current_day);
mCalendarView = findViewById(R.id.calendarView);
mTextCurrentDay = findViewById(R.id.tv_current_day);
mTextMonthDay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -83,24 +84,21 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
mCalendarView.scrollToCurrent();
//mCalendarView.addSchemeDate(getSchemeCalendar(2019, 6, 1, 0xFF40db25, "假"));
// int year = 2019;
// int month = 6;
// Map<String, Calendar> map = new HashMap<>();
// map.put(getSchemeCalendar(year, month, 3, 0xFF40db25, "假").toString(),
// getSchemeCalendar(year, month, 3, 0xFF40db25, "假"));
// map.put(getSchemeCalendar(year, month, 6, 0xFFe69138, "事").toString(),
// getSchemeCalendar(year, month, 6, 0xFFe69138, "事"));
// map.put(getSchemeCalendar(year, month, 9, 0xFFdf1356, "议").toString(),
// getSchemeCalendar(year, month, 9, 0xFFdf1356, "议"));
// map.put(getSchemeCalendar(year, month, 13, 0xFFedc56d, "记").toString(),
// getSchemeCalendar(year, month, 13, 0xFFedc56d, "记"));
// mCalendarView.addSchemeDate(map);
}
});
mCalendarLayout = findViewById(R.id.calendarLayout);
mCalendarView.setOnCalendarSelectListener(this);
mCalendarView.setOnYearChangeListener(this);
mCalendarView.setOnClickCalendarPaddingListener(new CalendarView.OnClickCalendarPaddingListener() {
@Override
public void onClickCalendarPadding(float x, float y, boolean isMonthView,
Calendar adjacentCalendar, Object obj) {
Log.e("onClickCalendarPadding", " -- " + x + " " + y + " " + obj + " " + adjacentCalendar);
Toast.makeText(MixActivity.this,
adjacentCalendar.getYear() + "年,第" + obj + "周",
Toast.LENGTH_SHORT).show();
}
});
mTextYear.setText(String.valueOf(mCalendarView.getCurYear()));
mYear = mCalendarView.getCurYear();
mTextMonthDay.setText(mCalendarView.getCurMonth() + "月" + mCalendarView.getCurDay() + "日");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,20 @@ protected void onPreviewHook() {
mRadius = Math.min(mItemWidth, mItemHeight) / 11 * 5;
}

@Override
protected Object getClickCalendarPaddingObject(float x, float y,Calendar adjacentCalendar) {
return CalendarUtil.getWeekCountBetweenBothCalendar(mYear, 1, 1,
mYear, adjacentCalendar.getMonth(), adjacentCalendar.getDay(), getWeekStartWith());
}

@Override
protected void onDraw(Canvas canvas) {

int weekStart = CalendarUtil.getWeekCountBetweenBothCalendar(mYear, 1, 1,
mYear, mMonth, 1, 1);
mYear, mMonth, 1, getWeekStartWith());
int weekEnd = CalendarUtil.getWeekCountBetweenBothCalendar(mYear, 1, 1,
mYear, mMonth, CalendarUtil.getMonthDaysCount(mYear, mMonth), 1);
int width = dipToPx(getContext(),52);//left-padding
mYear, mMonth, CalendarUtil.getMonthDaysCount(mYear, mMonth), getWeekStartWith());
int width = dipToPx(getContext(), 52);//left-padding
int cx = width / 2;
int cy = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public MixWeekView(Context context) {
@Override
protected void onDraw(Canvas canvas) {

if(mItems == null || mItems.size() == 0){
if (mItems == null || mItems.size() == 0) {
return;
}
Calendar calendar = mItems.get(0);
int weekStart = CalendarUtil.getWeekCountBetweenBothCalendar(calendar.getYear(), 1, 1,
calendar.getYear(), calendar.getMonth(), calendar.getDay(), 1);
int width = dipToPx(getContext(),52);
calendar.getYear(), calendar.getMonth(), calendar.getDay(), getWeekStartWith());
int width = dipToPx(getContext(), 52);
int cx = width / 2;
int cy = 0;

Expand All @@ -115,6 +115,12 @@ protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}

@Override
protected Object getClickCalendarPaddingObject(float x, float y, Calendar adjacentCalendar) {
return CalendarUtil.getWeekCountBetweenBothCalendar(adjacentCalendar.getYear(), 1, 1,
adjacentCalendar.getYear(), adjacentCalendar.getMonth(), adjacentCalendar.getDay(), getWeekStartWith());
}

@Override
protected void onPreviewHook() {
mSolarTermTextPaint.setTextSize(mCurMonthLunarTextPaint.getTextSize());
Expand Down Expand Up @@ -155,7 +161,7 @@ protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasSc
canvas.drawCircle(cx, cy, mRadius, mCurrentDayPaint);
}

if(hasScheme){
if (hasScheme) {
canvas.drawCircle(x + mItemWidth - mPadding - mCircleRadius / 2, mPadding + mCircleRadius, mCircleRadius, mSchemeBasicPaint);

mTextPaint.setColor(calendar.getSchemeColor());
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_mix.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
app:selected_text_color="#fff"
app:selected_theme_color="#046cea"
app:week_background="#fff"
app:week_start_with="sun"
app:week_start_with="mon"
app:week_text_color="#e1e1e1"
app:week_view="com.haibin.calendarviewproject.mix.MixWeekView"
app:year_view_day_text_color="#333333"
Expand Down
4 changes: 2 additions & 2 deletions calendarview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
minSdkVersion 14
//noinspection OldTargetApi
targetSdkVersion 28
versionCode 370
versionName "3.7.0"
versionCode 371
versionName "3.7.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public abstract class BaseMonthView extends BaseView {
*/
protected int mNextDiff;


public BaseMonthView(Context context) {
super(context);
}
Expand Down Expand Up @@ -115,6 +116,7 @@ protected Calendar getIndex() {
return null;
}
if (mX <= mDelegate.getCalendarPaddingLeft() || mX >= getWidth() - mDelegate.getCalendarPaddingRight()) {
onClickCalendarPadding();
return null;
}
int indexX = (int) (mX - mDelegate.getCalendarPaddingLeft()) / mItemWidth;
Expand All @@ -123,8 +125,43 @@ protected Calendar getIndex() {
}
int indexY = (int) mY / mItemHeight;
int position = indexY * 7 + indexX;// 选择项
if (position >= 0 && position < mItems.size())
if (position >= 0 && position < mItems.size()) {
return mItems.get(position);
}
return null;
}

private void onClickCalendarPadding() {
if (mDelegate.mClickCalendarPaddingListener == null) {
return;
}
Calendar calendar = null;
int indexX = (int) (mX - mDelegate.getCalendarPaddingLeft()) / mItemWidth;
if (indexX >= 7) {
indexX = 6;
}
int indexY = (int) mY / mItemHeight;
int position = indexY * 7 + indexX;// 选择项
if (position >= 0 && position < mItems.size()) {
calendar = mItems.get(position);
}
if (calendar == null) {
return;
}
mDelegate.mClickCalendarPaddingListener.onClickCalendarPadding(mX, mY, true, calendar,
getClickCalendarPaddingObject(mX, mY, calendar));
}

/**
* 获取点击事件处的对象
*
* @param x x
* @param y y
* @param adjacentCalendar adjacent calendar
* @return obj can as null
*/
@SuppressWarnings("unused")
protected Object getClickCalendarPaddingObject(float x, float y, Calendar adjacentCalendar) {
return null;
}

Expand Down
31 changes: 26 additions & 5 deletions calendarview/src/main/java/com/haibin/calendarview/BaseView.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public abstract class BaseView extends View implements View.OnClickListener, Vie
/**
* 点击的x、y坐标
*/
float mX, mY;
protected float mX, mY;

/**
* 是否点击
Expand All @@ -142,6 +142,11 @@ public abstract class BaseView extends View implements View.OnClickListener, Vie
*/
int mCurrentItem = -1;

/**
* 周起始
*/
int mWeekStartWidth;

public BaseView(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -226,17 +231,18 @@ private void initPaint(Context context) {
*
* @param delegate delegate
*/
final void setup(CalendarViewDelegate delegate) {
final void setup(CalendarViewDelegate delegate) {
this.mDelegate = delegate;
mWeekStartWidth = mDelegate.getWeekStart();
updateStyle();
updateItemHeight();

initPaint();
}


final void updateStyle(){
if(mDelegate == null){
final void updateStyle() {
if (mDelegate == null) {
return;
}
this.mCurDayTextPaint.setColor(mDelegate.getCurDayTextColor());
Expand Down Expand Up @@ -295,7 +301,7 @@ final void addSchemesFromMap() {
for (Calendar a : mItems) {
if (mDelegate.mSchemeDatesMap.containsKey(a.toString())) {
Calendar d = mDelegate.mSchemeDatesMap.get(a.toString());
if(d == null){
if (d == null) {
continue;
}
a.setScheme(TextUtils.isEmpty(d.getScheme()) ? mDelegate.getSchemeText() : d.getScheme());
Expand Down Expand Up @@ -402,6 +408,21 @@ protected final boolean isInRange(Calendar calendar) {
*/
protected abstract void onDestroy();

protected int getWeekStartWith() {
return mDelegate != null ? mDelegate.getWeekStart() : CalendarViewDelegate.WEEK_START_WITH_SUN;
}


protected int getCalendarPaddingLeft() {
return mDelegate != null ? mDelegate.getCalendarPaddingLeft() : 0;
}


protected int getCalendarPaddingRight() {
return mDelegate != null ? mDelegate.getCalendarPaddingRight() : 0;
}


/**
* 初始化画笔相关
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ final int getEdgeIndex(boolean isMinEdge) {
* @return 获取点击的日历
*/
protected Calendar getIndex() {

if (mX <= mDelegate.getCalendarPaddingLeft() || mX >= getWidth() - mDelegate.getCalendarPaddingRight()) {
onClickCalendarPadding();
return null;
}

Expand All @@ -176,6 +176,42 @@ protected Calendar getIndex() {
}


private void onClickCalendarPadding() {
if (mDelegate.mClickCalendarPaddingListener == null) {
return;
}
Calendar calendar = null;
int indexX = (int) (mX - mDelegate.getCalendarPaddingLeft()) / mItemWidth;
if (indexX >= 7) {
indexX = 6;
}
int indexY = (int) mY / mItemHeight;
int position = indexY * 7 + indexX;// 选择项
if (position >= 0 && position < mItems.size()) {
calendar = mItems.get(position);
}
if (calendar == null) {
return;
}
mDelegate.mClickCalendarPaddingListener.onClickCalendarPadding(mX, mY, false, calendar,
getClickCalendarPaddingObject(mX, mY, calendar));
}

/**
* /**
* 获取点击事件处的对象
*
* @param x x
* @param y y
* @param adjacentCalendar adjacent calendar
* @return obj can as null
*/
@SuppressWarnings("unused")
protected Object getClickCalendarPaddingObject(float x, float y, Calendar adjacentCalendar) {
return null;
}


/**
* 更新显示模式
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static int getMonthViewLineCount(int year, int month, int weekStartWith,
* @param year 年
* @param month 月
* @param itemHeight 每项的高度
* @param weekStartWith 周起始
* @return 不需要多余行的高度
*/
public static int getMonthViewHeight(int year, int month, int itemHeight, int weekStartWith) {
Expand Down Expand Up @@ -414,6 +415,7 @@ public static int getWeekFromCalendarStartWithMinCalendar(Calendar calendar,
* @param minYearMonth maxYear 最小年份月份,like : 2017-07
* @param minYearDay 最小年份天
* @param week 从最小年份minYear月minYearMonth 日1 开始的第几周 week > 0
* @param weekStart 周起始
* @return 该星期的第一天日期
*/
public static Calendar getFirstCalendarStartWithMinCalendar(int minYear, int minYearMonth, int minYearDay, int week, int weekStart) {
Expand Down
Loading

0 comments on commit 18c6202

Please sign in to comment.