Skip to content

Commit

Permalink
尝试
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Mar 25, 2020
1 parent e6e8b08 commit 179493a
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 56 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_miui10.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
android:id="@+id/miui10Calendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:showNumberBackground="true"
>


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_month_adapter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultCalendar="week"
app:isShowNumberBackground="true"
app:showNumberBackground="true"
app:numberBackgroundAlphaColor="100"
app:numberBackgroundTextSize="250sp"
app:numberBackgroundTextColor="#398FE9">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.6.1'

//上传jcenter相关插件
classpath 'com.novoda:bintray-release:0.9'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 28 17:07:44 CST 2018
#Wed Mar 25 14:59:29 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.joda.time.LocalDate;

/**
* Created by necer on 2018/9/11.
*
* @author necer
* @date 2018/9/11
* qq群:127278900
*/
public class WeekPagerAdapter extends BasePagerAdapter {
Expand Down
16 changes: 13 additions & 3 deletions ncalendar/src/main/java/com/necer/calendar/BaseCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.necer.R;
import com.necer.adapter.BasePagerAdapter;
import com.necer.enumeration.CalendarBuild;
import com.necer.enumeration.MultipleNumModel;
Expand Down Expand Up @@ -98,10 +106,12 @@ public BaseCalendar(@NonNull Context context, @Nullable AttributeSet attributeSe

mCalendarBgColor = mAttrs.bgCalendarColor;
mFirstDayOfWeek = mAttrs.firstDayOfWeek;
mIsAllMonthSixLine = mAttrs.isAllMonthSixLine;
mIsLastNextMonthClickEnable = mAttrs.isLastNextMonthClickEnable;
mIsAllMonthSixLine = mAttrs.allMonthSixLine;
mIsLastNextMonthClickEnable = mAttrs.lastNextMonthClickEnable;

// setBackgroundColor(Color.YELLOW);


setBackgroundColor(mCalendarBgColor);
addOnPageChangeListener(new SimpleOnPageChangeListener() {
@Override
public void onPageSelected(final int position) {
Expand Down
19 changes: 10 additions & 9 deletions ncalendar/src/main/java/com/necer/painter/InnerPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.graphics.drawable.Drawable;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.necer.R;
import com.necer.calendar.ICalendar;
import com.necer.entity.CalendarDate;
Expand All @@ -24,7 +26,6 @@
import java.util.Map;

/**
*
* @author necer
* @date 2019/1/3
*/
Expand Down Expand Up @@ -69,13 +70,13 @@ public InnerPainter(Context context, ICalendar calendar) {
mReplaceLunarColorMap = new HashMap<>();
mStretchStrMap = new HashMap<>();

mDefaultCheckedBackground = context.getResources().getDrawable(mAttrs.defaultCheckedBackground);
mTodayCheckedBackground = context.getResources().getDrawable(mAttrs.todayCheckedBackground);
mDefaultCheckedBackground = ContextCompat.getDrawable(context, mAttrs.defaultCheckedBackground);
mTodayCheckedBackground = ContextCompat.getDrawable(context, mAttrs.todayCheckedBackground);

mDefaultCheckedPoint = context.getResources().getDrawable(mAttrs.defaultCheckedPoint);
mDefaultUnCheckedPoint = context.getResources().getDrawable(mAttrs.defaultUnCheckedPoint);
mTodayCheckedPoint = context.getResources().getDrawable(mAttrs.todayCheckedPoint);
mTodayUnCheckedPoint = context.getResources().getDrawable(mAttrs.todayUnCheckedPoint);
mDefaultCheckedPoint = ContextCompat.getDrawable(context, mAttrs.defaultCheckedPoint);
mDefaultUnCheckedPoint = ContextCompat.getDrawable(context, mAttrs.defaultUnCheckedPoint);
mTodayCheckedPoint = ContextCompat.getDrawable(context, mAttrs.todayCheckedPoint);
mTodayUnCheckedPoint = ContextCompat.getDrawable(context, mAttrs.todayUnCheckedPoint);


List<String> holidayList = CalendarUtil.getHolidayList();
Expand All @@ -99,12 +100,12 @@ private Paint getPaint() {

@Override
public void onDrawCalendarBackground(ICalendarView iCalendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {
if (iCalendarView.getCalendarType() == CalendarType.MONTH && mAttrs.isShowNumberBackground) {
if (iCalendarView.getCalendarType() == CalendarType.MONTH && mAttrs.showNumberBackground) {
mTextPaint.setTextSize(mAttrs.numberBackgroundTextSize);
mTextPaint.setColor(mAttrs.numberBackgroundTextColor);
int alphaColor = mAttrs.numberBackgroundAlphaColor * currentDistance / totalDistance;
mTextPaint.setAlpha(alphaColor);
canvas.drawText(String.valueOf(localDate.getMonthOfYear()), rectF.centerX(), getTextBaseLineY(rectF.centerY()), mTextPaint);
canvas.drawText(localDate.getMonthOfYear()+"", rectF.centerX(), getTextBaseLineY(rectF.centerY()), mTextPaint);
}
}

Expand Down
61 changes: 30 additions & 31 deletions ncalendar/src/main/java/com/necer/utils/AttrsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
import android.content.res.TypedArray;
import android.util.AttributeSet;

import androidx.core.content.ContextCompat;

import com.necer.R;
import com.necer.enumeration.CalendarState;

/**
* Created by necer on 2018/11/28.
*
* @author necer
* @date 2018/11/28
*/
public class AttrsUtil {


public static Attrs getAttrs(Context context, AttributeSet attributeSet) {
Attrs attrs = new Attrs();

TypedArray ta = context.obtainStyledAttributes(attributeSet, R.styleable.NCalendar);

attrs.todayCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedSolarTextColor, context.getResources().getColor(R.color.N_white));
attrs.todayUnCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_todayUnCheckedSolarTextColor, context.getResources().getColor(R.color.N_todaySolarUnCheckedTextColor));
attrs.defaultCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedSolarTextColor, context.getResources().getColor(R.color.N_defaultSolarTextColor));
attrs.defaultUnCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_defaultUnCheckedSolarTextColor, context.getResources().getColor(R.color.N_defaultSolarTextColor));
attrs.todayCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedSolarTextColor, ContextCompat.getColor(context,R.color.N_white));
attrs.todayUnCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_todayUnCheckedSolarTextColor, ContextCompat.getColor(context,R.color.N_todaySolarUnCheckedTextColor));
attrs.defaultCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedSolarTextColor, ContextCompat.getColor(context,R.color.N_defaultSolarTextColor));
attrs.defaultUnCheckedSolarTextColor = ta.getColor(R.styleable.NCalendar_defaultUnCheckedSolarTextColor, ContextCompat.getColor(context,R.color.N_defaultSolarTextColor));
attrs.solarTextSize = ta.getDimension(R.styleable.NCalendar_solarTextSize, context.getResources().getDimension(R.dimen.N_solarTextSize));

attrs.pointLocation = ta.getInt(R.styleable.NCalendar_pointLocation, Attrs.UP);
Expand All @@ -40,35 +43,33 @@ public static Attrs getAttrs(Context context, AttributeSet attributeSet) {
attrs.defaultCheckedWorkday = ta.getDrawable(R.styleable.NCalendar_defaultCheckedWorkday);
attrs.defaultUnCheckedWorkday = ta.getDrawable(R.styleable.NCalendar_defaultUnCheckedWorkday);

attrs.showHoliday = ta.getBoolean(R.styleable.NCalendar_showHoliday, context.getResources().getBoolean(R.bool.N_isShowHoliday));
attrs.showHoliday = ta.getBoolean(R.styleable.NCalendar_showHoliday, context.getResources().getBoolean(R.bool.N_showHoliday));
attrs.holidayWorkdayTextSize = ta.getDimension(R.styleable.NCalendar_holidayWorkdayTextSize, context.getResources().getDimension(R.dimen.N_holidayWorkdayTextSize));
attrs.holidayWorkdayDistance = ta.getDimension(R.styleable.NCalendar_holidayWorkdayDistance, context.getResources().getDimension(R.dimen.N_holidayWorkdayDistance));
attrs.holidayWorkdayLocation = ta.getInt(R.styleable.NCalendar_holidayWorkdayLocation, Attrs.TOP_RIGHT);
attrs.holidayText = ta.getString(R.styleable.NCalendar_holidayText);
attrs.workdayText = ta.getString(R.styleable.NCalendar_workdayText);
attrs.todayCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedHolidayTextColor, context.getResources().getColor(R.color.N_white));
attrs.todayUnCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedHolidayTextColor, context.getResources().getColor(R.color.N_holidayTextColor));
attrs.defaultCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedHolidayTextColor, context.getResources().getColor(R.color.N_holidayTextColor));
attrs.defaultUnCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedHolidayTextColor, context.getResources().getColor(R.color.N_holidayTextColor));
attrs.todayCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedWorkdayTextColor, context.getResources().getColor(R.color.N_white));
attrs.todayUnCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedWorkdayTextColor, context.getResources().getColor(R.color.N_workdayTextColor));
attrs.defaultCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedWorkdayTextColor, context.getResources().getColor(R.color.N_workdayTextColor));
attrs.defaultUnCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_defaultUnCheckedWorkdayTextColor, context.getResources().getColor(R.color.N_workdayTextColor));


attrs.showLunar = ta.getBoolean(R.styleable.NCalendar_showLunar, context.getResources().getBoolean(R.bool.N_isShowLunar));
attrs.todayCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedLunarTextColor, context.getResources().getColor(R.color.N_white));
attrs.todayUnCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_todayUnCheckedLunarTextColor, context.getResources().getColor(R.color.N_todayCheckedColor));
attrs.defaultCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedLunarTextColor, context.getResources().getColor(R.color.N_defaultLunarTextColor));
attrs.defaultUnCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_defaultUnCheckedLunarTextColor, context.getResources().getColor(R.color.N_defaultLunarTextColor));
attrs.todayCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedHolidayTextColor, ContextCompat.getColor(context,R.color.N_white));
attrs.todayUnCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedHolidayTextColor, ContextCompat.getColor(context,R.color.N_holidayTextColor));
attrs.defaultCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedHolidayTextColor, ContextCompat.getColor(context,R.color.N_holidayTextColor));
attrs.defaultUnCheckedHolidayTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedHolidayTextColor, ContextCompat.getColor(context,R.color.N_holidayTextColor));
attrs.todayCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedWorkdayTextColor, ContextCompat.getColor(context,R.color.N_white));
attrs.todayUnCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedWorkdayTextColor, ContextCompat.getColor(context,R.color.N_workdayTextColor));
attrs.defaultCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedWorkdayTextColor, ContextCompat.getColor(context,R.color.N_workdayTextColor));
attrs.defaultUnCheckedWorkdayTextColor = ta.getColor(R.styleable.NCalendar_defaultUnCheckedWorkdayTextColor, ContextCompat.getColor(context,R.color.N_workdayTextColor));

attrs.showLunar = ta.getBoolean(R.styleable.NCalendar_showLunar, context.getResources().getBoolean(R.bool.N_showLunar));
attrs.todayCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_todayCheckedLunarTextColor, ContextCompat.getColor(context,R.color.N_white));
attrs.todayUnCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_todayUnCheckedLunarTextColor, ContextCompat.getColor(context,R.color.N_todayCheckedColor));
attrs.defaultCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_defaultCheckedLunarTextColor, ContextCompat.getColor(context,R.color.N_defaultLunarTextColor));
attrs.defaultUnCheckedLunarTextColor = ta.getColor(R.styleable.NCalendar_defaultUnCheckedLunarTextColor, ContextCompat.getColor(context,R.color.N_defaultLunarTextColor));
attrs.lunarTextSize = ta.getDimension(R.styleable.NCalendar_lunarTextSize, context.getResources().getDimension(R.dimen.N_lunarTextSize));
attrs.lunarDistance = ta.getDimension(R.styleable.NCalendar_lunarDistance, context.getResources().getDimension(R.dimen.N_lunarDistance));


attrs.calendarHeight = (int) ta.getDimension(R.styleable.NCalendar_calendarHeight, context.getResources().getDimension(R.dimen.N_calendarHeight));
attrs.stretchCalendarHeight = (int) ta.getDimension(R.styleable.NCalendar_stretchCalendarHeight, context.getResources().getDimension(R.dimen.N_stretchCalendarHeight));
attrs.animationDuration = ta.getInt(R.styleable.NCalendar_animationDuration, context.getResources().getInteger(R.integer.N_animationDuration));
attrs.bgCalendarColor = ta.getColor(R.styleable.NCalendar_bgCalendarColor, context.getResources().getColor(R.color.N_white));
attrs.bgCalendarColor = ta.getColor(R.styleable.NCalendar_bgCalendarColor, ContextCompat.getColor(context,R.color.N_white));
attrs.firstDayOfWeek = ta.getInt(R.styleable.NCalendar_firstDayOfWeek, Attrs.SUNDAY);
attrs.defaultCalendar = ta.getInt(R.styleable.NCalendar_defaultCalendar, CalendarState.MONTH.getValue());

Expand All @@ -78,21 +79,19 @@ public static Attrs getAttrs(Context context, AttributeSet attributeSet) {

attrs.stretchTextSize = ta.getDimension(R.styleable.NCalendar_stretchTextSize, context.getResources().getDimension(R.dimen.N_stretchTextSize));
attrs.stretchTextDistance = ta.getDimension(R.styleable.NCalendar_stretchTextDistance, context.getResources().getDimension(R.dimen.N_stretchTextDistance));
attrs.stretchTextColor = ta.getColor(R.styleable.NCalendar_stretchTextColor, context.getResources().getColor(R.color.N_stretchTextColor));
attrs.stretchTextColor = ta.getColor(R.styleable.NCalendar_stretchTextColor,ContextCompat.getColor(context,R.color.N_stretchTextColor));

attrs.allMonthSixLine = ta.getBoolean(R.styleable.NCalendar_allMonthSixLine, context.getResources().getBoolean(R.bool.N_isAllMonthSixLine));
attrs.showNumberBackground = ta.getBoolean(R.styleable.NCalendar_showNumberBackground, context.getResources().getBoolean(R.bool.N_isShowNumberBackground));
attrs.allMonthSixLine = ta.getBoolean(R.styleable.NCalendar_allMonthSixLine, context.getResources().getBoolean(R.bool.N_allMonthSixLine));
attrs.showNumberBackground = ta.getBoolean(R.styleable.NCalendar_showNumberBackground, context.getResources().getBoolean(R.bool.N_showNumberBackground));
attrs.numberBackgroundTextSize = ta.getDimension(R.styleable.NCalendar_numberBackgroundTextSize, context.getResources().getDimension(R.dimen.N_numberBackgroundTextSize));
attrs.numberBackgroundTextColor = ta.getColor(R.styleable.NCalendar_numberBackgroundTextColor, context.getResources().getColor(R.color.N_todaySolarUnCheckedTextColor));
attrs.numberBackgroundTextColor = ta.getColor(R.styleable.NCalendar_numberBackgroundTextColor, ContextCompat.getColor(context,R.color.N_todaySolarUnCheckedTextColor));
attrs.numberBackgroundAlphaColor = ta.getInt(R.styleable.NCalendar_numberBackgroundAlphaColor, context.getResources().getInteger(R.integer.N_numberBackgroundAlphaColor));

attrs.lastNextMonthClickEnable = ta.getBoolean(R.styleable.NCalendar_lastNextMonthClickEnable, context.getResources().getBoolean(R.bool.N_isLastNextMonthClickEnable));
attrs.lastNextMonthClickEnable = ta.getBoolean(R.styleable.NCalendar_lastNextMonthClickEnable, context.getResources().getBoolean(R.bool.N_lastNextMonthClickEnable));
attrs.todayCheckedBackground = ta.getResourceId(R.styleable.NCalendar_todayCheckedBackground, R.drawable.n_bg_checked_today);
attrs.defaultCheckedBackground = ta.getResourceId(R.styleable.NCalendar_defaultCheckedBackground, R.drawable.n_bg_checked_default);


ta.recycle();

return attrs;

}
Expand Down
11 changes: 9 additions & 2 deletions ncalendar/src/main/java/com/necer/view/CalendarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.necer.R;
import com.necer.calendar.BaseCalendar;
import com.necer.enumeration.CalendarType;
import com.necer.helper.CalendarHelper;
Expand All @@ -17,7 +24,8 @@
import java.util.List;

/**
* Created by necer on 2018/9/11.
* @author necer
* @date 2018/9/11
* qq群:127278900
*/
public class CalendarView extends View implements ICalendarView {
Expand All @@ -38,7 +46,6 @@ public CalendarView(Context context, BaseCalendar calendar, LocalDate initialDat

@Override
protected void onDraw(Canvas canvas) {

CalendarPainter calendarPainter = mCalendarHelper.getCalendarPainter();
//绘制背景
drawBg(canvas, calendarPainter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import androidx.viewpager.widget.ViewPager;

/**
* Created by necer on 2020/3/20.
*
* @author necer
* @date 2020/3/20
*/
public class CalendarViewPager extends ViewPager {

Expand Down
3 changes: 3 additions & 0 deletions ncalendar/src/main/java/com/necer/view/ICalendarView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

import java.util.List;

/**
* @author necer
*/
public interface ICalendarView {


Expand Down
10 changes: 5 additions & 5 deletions ncalendar/src/main/res/values/bools.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="N_isShowHoliday">true</bool>
<bool name="N_isShowLunar">true</bool>
<bool name="N_isAllMonthSixLine">false</bool>
<bool name="N_isShowNumberBackground">false</bool>
<bool name="N_isLastNextMonthClickEnable">true</bool>
<bool name="N_showHoliday">true</bool>
<bool name="N_showLunar">true</bool>
<bool name="N_allMonthSixLine">false</bool>
<bool name="N_showNumberBackground">false</bool>
<bool name="N_lastNextMonthClickEnable">true</bool>
</resources>

0 comments on commit 179493a

Please sign in to comment.