diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 45a57aa8..fb7f4a8a 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,9 +1,6 @@ - - - - + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..bfe22bea --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 0ad9e52f..55fa4b31 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,9 +4,10 @@ diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml index a5f05cd8..1d883acc 100644 --- a/.idea/jarRepositories.xml +++ b/.idea/jarRepositories.xml @@ -21,5 +21,10 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 5e8a9652..a9062422 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,11 +2,15 @@ - + + + + - - + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460d..00000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README-5.x.md b/README-5.x.md new file mode 100644 index 00000000..89b28d26 --- /dev/null +++ b/README-5.x.md @@ -0,0 +1,224 @@ +# 安卓日历 NCalendar + +## 特点: + + - 3种常见日历交互方式,MIUI系统日历:miui9、miui10、华为emui,miui9和钉钉日历类似,华为emui和365日历类似 + - 月周滑动切换,月周不选中 + - 支持多选,设置多选的数量 + - 支持设置默认视图,默认周日历或者月日历 + - 支持周状态固定,下拉刷新等 + - 支持设置一周开始的是周一还是周日 + - 可设置日期区间,默认区间从1901-01-01到2099-12-31 + - 支持农历,节气、法定节假日等 + - 支持添加指示点及设置指示点位置 + - 支持各种颜色、距离、位置等属性 + - 支持日历和列表之间添加view + - 支持替换农历、颜色等 + - 支持自定义日历页面 + - 支持内部TargetView为任意View + - 支持日历拉伸功能 + - 支持适配器模式自定义日历 + +## 效果图 +|Miui9Calendar|Miui10Calendar|EmuiCalendar| +|:---:|:---:|:---:| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/miui9_gif.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/miui10_gif.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/emui_gif.gif)| + +|周固定,下拉刷新|日历和子view添加其他view|自定义日历界面(LigaturePainter)| +|:---:|:---:|:---:| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/week_hold.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/addview.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/LigaturePainter.png)| + +|默认不选中|默认多选|自定义日历界面(TicketPainter)| +|:---:|:---:|:---:| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/111.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/222.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/TicketPainter.png)| + + +|ViewPager|普通View|demo功能预览| +|:---:|:---:|:---:| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/viewpager.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/general.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/demo.png)| + + +|日历拉伸| +|:---:| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/Stretch.gif)| + +# 下载demo: +[下载demo](https://github.com/yannecer/NCalendar/releases/download/4.3.0/4.3.0.apk) + + +## 使用方法 + + +#### 项目build文件 + +``` + android { + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + ... + } + +``` + +#### Gradle +``` +implementation 'com.necer.ncalendar:ncalendar:5.0.2' + +``` + +#### 简单使用 + +``` + miui9 和 钉钉日历 + + < + + + Miui10Calendar EmuiCalendar 用法类似 + +``` + +#### 单个月日历,单个周日历 + + +``` + 月日历 + + + 周日历 + + +``` + +### [详细用法](https://github.com/yannecer/NCalendar/wiki/%E8%AF%A6%E7%BB%86%E7%94%A8%E6%B3%95) + +*** + +## 自定义属性 +``` +5.x版本更新了大量的自定义属性 +``` +### [自定义属性](https://github.com/yannecer/NCalendar/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7) + +*** + +## 日历Api +``` +日历提供了各种可能用到的方法、回调,5.x版本增加了日历日期变化的行为参数,区分了各种引起日历变化的不同的操作 +``` +### [日历Api](https://github.com/yannecer/NCalendar/wiki/%E6%97%A5%E5%8E%86Api) +### [日历Api相关类说明](https://github.com/yannecer/NCalendar/wiki/Api%E7%9B%B8%E5%85%B3%E7%B1%BB%E8%AF%B4%E6%98%8E) + +*** +## 日历设置时间标记、替换文字等Api + +``` +日历设置时间标记、替换文字的Api,只对InnerPainter有效,如果是自定义日历UI,则这些方法需要自己实现, +可参考InnerPainter相关代码 + +``` +### [日历设置时间标记、替换文字](https://github.com/yannecer/NCalendar/wiki/%E6%97%A5%E5%8E%86%E8%AE%BE%E7%BD%AE%E6%A0%87%E8%AE%B0%E3%80%81%E6%9B%BF%E6%8D%A2%E6%96%87%E5%AD%97) +*** + +## 自定义日历UI +``` +如果自定义属性不能满足日历ui要求,可以使用自定义页面实现个性化需求,项目提供了两种自定义UI的方式, +1、实现CalendarPainter接口,通过Canvas绘制 +2、继承CalendarAdapter抽象类,和ListView的BaseAdapter用法相似 +``` +### [自定义日历UI](https://github.com/yannecer/NCalendar/wiki/%E8%87%AA%E5%AE%9A%E4%B9%89%E6%97%A5%E5%8E%86UI) + +*** + + +### 交流群 + +技术交流QQ群:127278900 (请先仔细看文档,然后再进群发问,上方加粗字体有下载demo链接) + + + +*** +### 常见问题 +``` +1、Activity初始化onCreate中调用jumpDate闪退 + 页面初始化时,日历还未完成初始化,可以使用 setInitializeDate 方法完成初始页面的日期选定,或者使用日历对象post方法设置jumpdate + miui10Calendar.post(new Runnable() { + @Override + public void run() { + miui10Calendar.jumpDate("2021-01-01"); + } + }); + +2、日历UI问题,请使用自定义CalendarPainter,简单的做法是,复制库中InnerPainter,修改绘制的部分,然后给日历设置CalendarPainter + miui10Calendar.setCalendarPainter(myCalendarPainter); + +``` + +## 感谢: + +项目中日期计算使用 [joda-time](https://github.com/JodaOrg/joda-time)
+感谢同事 **魏昌琳** 提出的优化建议
+感觉农历和节气数据工具类的作者
+ + +*** + +## 更新日志 +* 5.0.2
修复Android9日期变化回调多次的bug,增加2021年法定休班日 +* 5.0.1
修复2020年腊月二十九为除夕的描述 +* 5.0.0
重写InnerPainter,增加大量属性、优化跳转逻辑等 +* 4.4.1
新增跳转月份的方法 +* 4.4.0
新增适配器模式自定义页面 +* 4.3.8
新增月日历上下月是否可点击的属性 isLastNextMonthClickEnable +* 4.3.7
修复选中月初月末,实际月份回调bug +* 4.3.6
增加数字背景以及渐变效果 +* 4.3.4
修复周状态下滑动卡顿的bug +* 4.3.3
修复莫名跳转2099年的bug,增加是否每个月都是6行的属性 +* 4.3.2
增加日历拉伸功能 +* 4.2.0
支持任意非滑动的View,ViewPger等 +* 4.1.2
完善LigaturePainter +* 4.1.1
修改选中模式为枚举,demo增加了两种自定义CalendarPainter +* 4.1.0
优化onDraw效率、修改CalendarPainter回调参数、新增多选日期数量 +* 4.0.4
修复某些情况下选中回调返回null的bug +* 4.0.2
修复节气不显示的bug +* 4.0.1
1、新增月周切换日历多选
2、新增默认不选中折叠
3、新增翻页默认选中每月1号
4、修复设置左右padding偏差 + + + + + + +License +------- + + + Copyright 2018 necer + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/README.md b/README.md index 5c2276bc..28bcc1fd 100644 --- a/README.md +++ b/README.md @@ -2,45 +2,45 @@ ## 特点: - - 3种常见日历交互方式,MIUI系统日历:miui9、miui10、华为emui,miui9和钉钉日历类似,华为emui和365日历类似 - - 月周滑动切换,月周不选中 - - 支持多选,设置多选的数量 - - 支持设置默认视图,默认周日历或者月日历 - - 支持周状态固定,下拉刷新等 - - 支持设置一周开始的是周一还是周日 - - 可设置日期区间,默认区间从1901-01-01到2099-12-31 - - 支持农历,节气、法定节假日等 - - 支持添加指示点及设置指示点位置 - - 支持各种颜色、距离、位置等属性 - - 支持日历和列表之间添加view - - 支持替换农历、颜色等 - - 支持自定义日历页面 - - 支持内部TargetView为任意View - - 支持日历拉伸功能 - - 支持适配器模式自定义日历 - -## 效果图 -|Miui9Calendar|Miui10Calendar|EmuiCalendar| -|:---:|:---:|:---:| -|![](https://github.com/yannecer/NCalendar/blob/master/app/miui9_gif.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/miui10_gif.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/emui_gif.gif)| +- 月日历、周日历、月周切换 +- 月周滑动切换,月周不选中 +- 支持多选,设置多选的数量 +- 支持设置默认视图,默认周日历或者月日历 +- 支持周状态固定,下拉刷新等 +- 支持设置一周开始的是周一还是周日 +- 可设置日期区间,默认区间从1901-01-01到2099-12-31 +- 支持农历,节气、法定节假日等 +- 支持添加指示点及设置指示点位置 +- 支持各种颜色、距离、位置等属性 +- 支持日历和列表之间添加view +- 支持替换农历、颜色等 +- 支持自定义日历页面 +- 支持内部TargetView为任意View +- 支持日历拉伸功能 +- 支持适配器模式自定义日历 + +## 效果图 +| 效果1 | 效果2| 效果3| +|:--------------------------------------------------------------------------------:|:--:|:---:| +| ![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/miui9_gif.gif) |![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/miui10_gif.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/emui_gif.gif)| |周固定,下拉刷新|日历和子view添加其他view|自定义日历界面(LigaturePainter)| |:---:|:---:|:---:| -|![](https://github.com/yannecer/NCalendar/blob/master/app/week_hold.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/addview.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/LigaturePainter.png)| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/week_hold.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/addview.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/LigaturePainter.png)| |默认不选中|默认多选|自定义日历界面(TicketPainter)| |:---:|:---:|:---:| -|![](https://github.com/yannecer/NCalendar/blob/master/app/111.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/222.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/TicketPainter.png)| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/111.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/222.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/TicketPainter.png)| |ViewPager|普通View|demo功能预览| |:---:|:---:|:---:| -|![](https://github.com/yannecer/NCalendar/blob/master/app/viewpager.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/general.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/demo.png)| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/viewpager.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/general.gif)|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/demo.png)| |日历拉伸| |:---:| -|![](https://github.com/yannecer/NCalendar/blob/master/app/Stretch.gif)| +|![](https://github.com/yannecer/NCalendar/blob/master/app/doc/pic/Stretch.gif)| # 下载demo: [下载demo](https://github.com/yannecer/NCalendar/releases/download/4.3.0/4.3.0.apk) @@ -52,39 +52,24 @@ #### 项目build文件 ``` - android { - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - ... - } ``` #### Gradle ``` -implementation 'com.necer.ncalendar:ncalendar:5.0.2' + ``` #### 简单使用 ``` - miui9 和 钉钉日历 - - < - - - Miui10Calendar EmuiCalendar 用法类似 + android:layout_height="match_parent" /> ``` @@ -93,18 +78,20 @@ implementation 'com.necer.ncalendar:ncalendar:5.0.2' ``` 月日历 - + android:layout_height="match_parent" + app:defaultCalendar="month"/> 周日历 - + android:layout_height="match_parent" + app:defaultCalendar="week"/> ``` -### [详细用法](https://github.com/yannecer/NCalendar/wiki/%E8%AF%A6%E7%BB%86%E7%94%A8%E6%B3%95) + *** @@ -170,14 +157,21 @@ implementation 'com.necer.ncalendar:ncalendar:5.0.2' ## 感谢: -项目中日期计算使用 [joda-time](https://github.com/JodaOrg/joda-time)
-感谢同事 **魏昌琳** 提出的优化建议
-感觉农历和节气数据工具类的作者
+农历和节气数据工具类来自 [Hutool](https://github.com/dromara/hutool)
*** ## 更新日志 + +* 6.0.0
1、日历中日期使用```java.time.LocalDate```,因此```minSdkVersion```最低版本必须为```26``` + 2、去除```MonthCalendar```和```WeekCalendar```,单独月日历和周日历整合进```NCalendar``` + 3、动画切换改为```Draw```绘制 + 4、加入阻断动画和快速滑动处理 + 5、重构减少近半的代码量 + 6、农历、节气等数据改为```Hutool```工具来 + 7、去除```miui9```等几种动画效果,保留了最普遍的```Miui10```的效果 + * 5.0.2
修复Android9日期变化回调多次的bug,增加2021年法定休班日 * 5.0.1
修复2020年腊月二十九为除夕的描述 * 5.0.0
重写InnerPainter,增加大量属性、优化跳转逻辑等 diff --git a/app/app-debug.apk b/app/app-debug.apk deleted file mode 100644 index 483d2df1..00000000 Binary files a/app/app-debug.apk and /dev/null differ diff --git a/app/build.gradle b/app/build.gradle index db9ebb46..fdea7fa5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,36 +1,45 @@ -apply plugin: 'com.android.application' +plugins { + id 'com.android.application' + id 'kotlin-android' +} android { + compileSdkVersion 34 + buildToolsVersion "29.0.3" - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - - compileSdkVersion 28 defaultConfig { - applicationId "com.necer.ncalendar" - minSdkVersion 15 - targetSdkVersion 28 - versionCode 2 - versionName "5.0.1" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + applicationId "com.necer.ncalendar.demo" + minSdkVersion 26 + targetSdkVersion 34 + versionCode 1 + versionName "6.0.0" + } + buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.0' - testImplementation 'junit:junit:4.12' - implementation project(':ncalendar') - implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.2' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'com.google.android.material:material:1.0.0' -} + implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0' + implementation project(path: ':ncalendar') + +} \ No newline at end of file diff --git a/app/doc/app/app-debug6.0.apk b/app/doc/app/app-debug6.0.apk new file mode 100644 index 00000000..acbf5784 Binary files /dev/null and b/app/doc/app/app-debug6.0.apk differ diff --git a/app/111.gif b/app/doc/pic/111.gif similarity index 100% rename from app/111.gif rename to app/doc/pic/111.gif diff --git a/app/222.gif b/app/doc/pic/222.gif similarity index 100% rename from app/222.gif rename to app/doc/pic/222.gif diff --git a/app/LigaturePainter.png b/app/doc/pic/LigaturePainter.png similarity index 100% rename from app/LigaturePainter.png rename to app/doc/pic/LigaturePainter.png diff --git a/app/Stretch.gif b/app/doc/pic/Stretch.gif similarity index 100% rename from app/Stretch.gif rename to app/doc/pic/Stretch.gif diff --git a/app/TicketPainter.png b/app/doc/pic/TicketPainter.png similarity index 100% rename from app/TicketPainter.png rename to app/doc/pic/TicketPainter.png diff --git a/app/add_view.png b/app/doc/pic/add_view.png similarity index 100% rename from app/add_view.png rename to app/doc/pic/add_view.png diff --git a/app/add_view1.png b/app/doc/pic/add_view1.png similarity index 100% rename from app/add_view1.png rename to app/doc/pic/add_view1.png diff --git a/app/addview.gif b/app/doc/pic/addview.gif similarity index 100% rename from app/addview.gif rename to app/doc/pic/addview.gif diff --git a/app/demo.png b/app/doc/pic/demo.png similarity index 100% rename from app/demo.png rename to app/doc/pic/demo.png diff --git a/app/emui_gif.gif b/app/doc/pic/emui_gif.gif similarity index 100% rename from app/emui_gif.gif rename to app/doc/pic/emui_gif.gif diff --git a/app/general.gif b/app/doc/pic/general.gif similarity index 100% rename from app/general.gif rename to app/doc/pic/general.gif diff --git a/app/miui10_gif.gif b/app/doc/pic/miui10_gif.gif similarity index 100% rename from app/miui10_gif.gif rename to app/doc/pic/miui10_gif.gif diff --git a/app/miui9_gif.gif b/app/doc/pic/miui9_gif.gif similarity index 100% rename from app/miui9_gif.gif rename to app/doc/pic/miui9_gif.gif diff --git a/app/month.png b/app/doc/pic/month.png similarity index 100% rename from app/month.png rename to app/doc/pic/month.png diff --git a/app/viewpager.gif b/app/doc/pic/viewpager.gif similarity index 100% rename from app/viewpager.gif rename to app/doc/pic/viewpager.gif diff --git a/app/week.png b/app/doc/pic/week.png similarity index 100% rename from app/week.png rename to app/doc/pic/week.png diff --git a/app/week_hold.gif b/app/doc/pic/week_hold.gif similarity index 100% rename from app/week_hold.gif rename to app/doc/pic/week_hold.gif diff --git a/app/src/androidTest/java/necer/ncalendardemo/ExampleInstrumentedTest.java b/app/src/androidTest/java/necer/ncalendardemo/ExampleInstrumentedTest.java deleted file mode 100644 index c078844a..00000000 --- a/app/src/androidTest/java/necer/ncalendardemo/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package necer.ncalendardemo; - -import android.content.Context; -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumentation test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertEquals("necer.ncalendardemo", appContext.getPackageName()); - } -} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 583ff2e1..90bedf81 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,8 @@ android:supportsRtl="true" android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning"> - + @@ -70,18 +71,5 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/necer/ncalendar/TestActivity2.java b/app/src/main/java/com/necer/ncalendar/TestActivity2.java index 62c383a3..d03265a3 100644 --- a/app/src/main/java/com/necer/ncalendar/TestActivity2.java +++ b/app/src/main/java/com/necer/ncalendar/TestActivity2.java @@ -2,16 +2,16 @@ import android.os.Bundle; -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.MonthCalendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.DateChangeBehavior; import com.necer.listener.OnCalendarChangedListener; -import org.joda.time.LocalDate; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import java.time.LocalDate; + /** * Created by necer on 2020/3/24. */ @@ -23,12 +23,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_test2); - MonthCalendar monthCalendar = findViewById(R.id.monthCalendar); + NCalendar monthCalendar = findViewById(R.id.monthCalendar); monthCalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { } + }); } diff --git a/app/src/main/java/com/necer/ncalendar/activity/CustomCalendarActivity.java b/app/src/main/java/com/necer/ncalendar/activity/CustomCalendarActivity.java index c193689b..b3e603d0 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/CustomCalendarActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/CustomCalendarActivity.java @@ -5,23 +5,23 @@ import androidx.appcompat.app.AppCompatActivity; import android.view.View; -import com.necer.calendar.Miui10Calendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.CheckModel; import com.necer.ncalendar.R; import com.necer.ncalendar.painter.LigaturePainter; import com.necer.ncalendar.painter.TicketPainter; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.HashMap; import java.util.Map; /** - * Created by necer on 2019/1/4. + * Created by necer on 2024/1/4. */ public class CustomCalendarActivity extends AppCompatActivity { - Miui10Calendar miui10Calendar; + NCalendar miui10Calendar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -37,25 +37,27 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public void ligaturePainter(View view) { LigaturePainter painter = new LigaturePainter(this); miui10Calendar.setCalendarPainter(painter); + miui10Calendar.notifyCalendar(); } public void ticketPainter(View view) { TicketPainter ticketPainter = new TicketPainter(this, miui10Calendar); Map priceMap = new HashMap<>(); - priceMap.put(new LocalDate("2019-06-07"), "¥350"); - priceMap.put(new LocalDate("2019-07-07"), "¥350"); - priceMap.put(new LocalDate("2019-06-30"), "¥350"); - priceMap.put(new LocalDate("2019-07-03"), "¥350"); - priceMap.put(new LocalDate("2019-07-04"), "¥350"); - priceMap.put(new LocalDate("2019-07-10"), "¥350"); - priceMap.put(new LocalDate("2019-07-15"), "¥350"); - priceMap.put(new LocalDate("2019-07-30"), "¥350"); - priceMap.put(new LocalDate("2019-08-04"), "¥350"); - priceMap.put(new LocalDate("2019-08-29"), "¥350"); + priceMap.put(LocalDate.parse("2024-06-07"), "¥350"); + priceMap.put(LocalDate.parse("2024-07-07"), "¥350"); + priceMap.put(LocalDate.parse("2024-06-30"), "¥350"); + priceMap.put(LocalDate.parse("2024-07-03"), "¥350"); + priceMap.put(LocalDate.parse("2024-07-04"), "¥350"); + priceMap.put(LocalDate.parse("2024-07-10"), "¥350"); + priceMap.put(LocalDate.parse("2024-07-15"), "¥350"); + priceMap.put(LocalDate.parse("2024-07-30"), "¥350"); + priceMap.put(LocalDate.parse("2024-08-04"), "¥350"); + priceMap.put(LocalDate.parse("2024-08-29"), "¥350"); ticketPainter.setPriceMap(priceMap); miui10Calendar.setCalendarPainter(ticketPainter); + miui10Calendar.notifyCalendar(); } } diff --git a/app/src/main/java/com/necer/ncalendar/activity/DingAdapterActivity.java b/app/src/main/java/com/necer/ncalendar/activity/DingAdapterActivity.java deleted file mode 100644 index cc0d26ec..00000000 --- a/app/src/main/java/com/necer/ncalendar/activity/DingAdapterActivity.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.necer.ncalendar.activity; - -import android.content.Context; -import android.graphics.Color; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.ICalendar; -import com.necer.entity.CalendarDate; -import com.necer.enumeration.CalendarType; -import com.necer.enumeration.DateChangeBehavior; -import com.necer.listener.OnCalendarChangedListener; -import com.necer.ncalendar.R; -import com.necer.painter.CalendarAdapter; -import com.necer.utils.CalendarUtil; -import com.necer.view.ICalendarView; - -import org.joda.time.LocalDate; - -import java.util.List; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -public class DingAdapterActivity extends AppCompatActivity { - - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_adapter); - - - ICalendar miui10Calendar = findViewById(R.id.miui10Calendar); - miui10Calendar.setCalendarAdapter(new DingAdapter()); - // miui10Calendar.setSelectedMode(SelectedModel.MULTIPLE); - miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { - @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { - Log.e("onCalendarChange", "onCalendarChange:::" + localDate); - } - - }); - - } - - - - public static class DingAdapter extends CalendarAdapter { - @Override - public View getCalendarItemView(Context context) { - return LayoutInflater.from(context).inflate(R.layout.item_calendar, null); - } - - - @Override - public void onBindToadyView(View view, LocalDate localDate, List totalCheckedDateList) { - - View ll_content = view.findViewById(R.id.ll_content); - - TextView tv_item = view.findViewById(R.id.tv_item); - - tv_item.setText(String.valueOf(localDate.getDayOfMonth())); - - setLunar(view, localDate, totalCheckedDateList); - - if (totalCheckedDateList.contains(localDate)) { - tv_item.setTextColor(Color.WHITE); - ll_content.setBackgroundResource(R.drawable.bg_checked_ding); - } else { - tv_item.setTextColor(Color.BLACK); - ll_content.setBackgroundResource(R.drawable.bg_unchecked); - } - } - - @Override - public void onBindCurrentMonthOrWeekView(View view, LocalDate localDate, List totalCheckedDateList) { - - View ll_content = view.findViewById(R.id.ll_content); - - TextView tv_item = view.findViewById(R.id.tv_item); - tv_item.setTextColor(Color.BLACK); - tv_item.setText(String.valueOf(localDate.getDayOfMonth())); - - setLunar(view, localDate, totalCheckedDateList); - - if (totalCheckedDateList.contains(localDate)) { - tv_item.setTextColor(Color.WHITE); - ll_content.setBackgroundResource(R.drawable.bg_checked_ding); - } else { - tv_item.setTextColor(Color.BLACK); - ll_content.setBackgroundResource(R.drawable.bg_unchecked); - } - - } - - @Override - public void onBindLastOrNextMonthView(View view, LocalDate localDate, List totalCheckedDateList) { - View ll_content = view.findViewById(R.id.ll_content); - TextView tv_item = view.findViewById(R.id.tv_item); - tv_item.setText(String.valueOf(localDate.getDayOfMonth())); - setLunar(view, localDate, totalCheckedDateList); - if (totalCheckedDateList.contains(localDate)) { - tv_item.setTextColor(Color.WHITE); - ll_content.setBackgroundResource(R.drawable.bg_checked_ding_last_next); - } else { - tv_item.setTextColor(Color.GRAY); - ll_content.setBackgroundResource(R.drawable.bg_unchecked); - } - } - - - private void setLunar(View view, LocalDate localDate, List selectedDateList) { - - TextView tv_lunar = view.findViewById(R.id.tv_lunar); - CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate); - tv_lunar.setText(calendarDate.lunar.lunarOnDrawStr); - if (selectedDateList.contains(localDate)) { - tv_lunar.setTextColor(Color.WHITE); - } else { - tv_lunar.setTextColor(Color.GRAY); - } - } - } - -} diff --git a/app/src/main/java/com/necer/ncalendar/activity/GeneralAdapterActivity.java b/app/src/main/java/com/necer/ncalendar/activity/GeneralAdapterActivity.java deleted file mode 100644 index 185ffe03..00000000 --- a/app/src/main/java/com/necer/ncalendar/activity/GeneralAdapterActivity.java +++ /dev/null @@ -1,117 +0,0 @@ -package com.necer.ncalendar.activity; - -import android.content.Context; -import android.graphics.Color; -import android.os.Bundle; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.ICalendar; -import com.necer.entity.CalendarDate; -import com.necer.enumeration.DateChangeBehavior; -import com.necer.listener.OnCalendarChangedListener; -import com.necer.ncalendar.R; -import com.necer.painter.CalendarAdapter; -import com.necer.utils.CalendarUtil; - -import org.joda.time.LocalDate; - -import java.util.List; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -public class GeneralAdapterActivity extends AppCompatActivity { - - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.activity_adapter); - - - ICalendar miui10Calendar = findViewById(R.id.miui10Calendar); - miui10Calendar.setCalendarAdapter(new GeneralAdapter()); - - miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { - @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { - Log.e("onCalendarChange", "onCalendarChange:::" + localDate); - } - - }); - - } - - - public static class GeneralAdapter extends CalendarAdapter { - @Override - public View getCalendarItemView(Context context) { - return LayoutInflater.from(context).inflate(R.layout.item_calendar, null); - } - - @Override - public void onBindToadyView(View view, LocalDate localDate, List totalCheckedDateList) { - - View ll_content = view.findViewById(R.id.ll_content); - - TextView tv_item = view.findViewById(R.id.tv_item); - tv_item.setTextColor(Color.RED); - tv_item.setText(String.valueOf(localDate.getDayOfMonth())); - - setLunar(view, localDate); - if (totalCheckedDateList.contains(localDate)) { - ll_content.setBackgroundResource(R.drawable.bg_today_checked); - } else { - ll_content.setBackgroundResource(R.drawable.bg_unchecked); - } - - } - - @Override - public void onBindCurrentMonthOrWeekView(View view, LocalDate localDate, List totalCheckedDateList) { - - View ll_content = view.findViewById(R.id.ll_content); - - TextView tv_item = view.findViewById(R.id.tv_item); - tv_item.setTextColor(Color.BLACK); - tv_item.setText(String.valueOf(localDate.getDayOfMonth())); - - setLunar(view, localDate); - - if (totalCheckedDateList.contains(localDate)) { - ll_content.setBackgroundResource(R.drawable.bg_checked); - } else { - ll_content.setBackgroundResource(R.drawable.bg_unchecked); - } - - } - - @Override - public void onBindLastOrNextMonthView(View view, LocalDate localDate, List totalCheckedDateList) { - View ll_content = view.findViewById(R.id.ll_content); - TextView tv_item = view.findViewById(R.id.tv_item); - tv_item.setTextColor(Color.GRAY); - tv_item.setText(String.valueOf(localDate.getDayOfMonth())); - - setLunar(view, localDate); - if (totalCheckedDateList.contains(localDate)) { - ll_content.setBackgroundResource(R.drawable.bg_last_next_checked); - } else { - ll_content.setBackgroundResource(R.drawable.bg_unchecked); - } - } - - - private void setLunar(View view, LocalDate localDate) { - TextView tv_lunar = view.findViewById(R.id.tv_lunar); - CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate); - tv_lunar.setText(calendarDate.lunar.lunarOnDrawStr); - } - } - -} diff --git a/app/src/main/java/com/necer/ncalendar/activity/MainActivity.java b/app/src/main/java/com/necer/ncalendar/activity/MainActivity.java index 9f7d32fd..6bdf06dd 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/MainActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/MainActivity.java @@ -113,10 +113,6 @@ public void test(View view) { startActivity(new Intent(this, TestActivity.class)); } - public void testAdapter(View view) { - startActivity(new Intent(this, TestAdapterActivity.class)); - } - private Intent getNewIntent(Class clazz, CheckModel checkModel, String title) { Intent intent = new Intent(this, clazz); diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestAdapterActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestAdapterActivity.java deleted file mode 100644 index ccd8db61..00000000 --- a/app/src/main/java/com/necer/ncalendar/activity/TestAdapterActivity.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.necer.ncalendar.activity; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; - -import com.necer.ncalendar.R; - -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - -public class TestAdapterActivity extends AppCompatActivity { - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_test_adapter); - } - - - public void general(View view) { - - startActivity(new Intent(this, GeneralAdapterActivity.class)); - - } - - public void ding(View view) { - - startActivity(new Intent(this, DingAdapterActivity.class)); - } - - -} diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestAddViewActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestAddViewActivity.java index f8596f28..93614e0c 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestAddViewActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestAddViewActivity.java @@ -5,13 +5,13 @@ import androidx.appcompat.app.AppCompatActivity; import android.view.View; -import com.necer.calendar.Miui10Calendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.CalendarState; import com.necer.ncalendar.R; public class TestAddViewActivity extends AppCompatActivity { - private Miui10Calendar miui10Calendar; + private NCalendar miui10Calendar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestEmuiActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestEmuiActivity.java index 642aba7f..230b182e 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestEmuiActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestEmuiActivity.java @@ -6,16 +6,15 @@ import android.view.View; import android.widget.TextView; -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.EmuiCalendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.CalendarState; import com.necer.enumeration.DateChangeBehavior; import com.necer.listener.OnCalendarChangedListener; import com.necer.listener.OnCalendarMultipleChangedListener; import com.necer.ncalendar.R; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.List; @@ -24,7 +23,7 @@ */ public class TestEmuiActivity extends BaseActivity { - private EmuiCalendar emuiCalendar; + private NCalendar emuiCalendar; private TextView tv_result; @@ -39,24 +38,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { tv_result = findViewById(R.id.tv_result); emuiCalendar.setCheckMode(checkModel); - emuiCalendar.setDefaultCheckedFirstDate(true);//只在selectedMode==SINGLE_SELECTED有效 emuiCalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + localDate); - Log.d(TAG, "当前页面选中::" + localDate); - Log.e(TAG, "baseCalendar::" + baseCalendar); } }); emuiCalendar.setOnCalendarMultipleChangedListener(new OnCalendarMultipleChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + currPagerCheckedList.size() + "个 总共选中" + totalCheckedList.size() + "个"); - Log.d(TAG, year + "年" + month + "月"); - Log.d(TAG, "当前页面选中::" + currPagerCheckedList); - Log.d(TAG, "全部选中::" + totalCheckedList); } }); diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestMiui10Activity.java b/app/src/main/java/com/necer/ncalendar/activity/TestMiui10Activity.java index 5296961f..75b35c8b 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestMiui10Activity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestMiui10Activity.java @@ -2,6 +2,7 @@ import android.graphics.Color; import android.graphics.drawable.Drawable; +import android.icu.util.ChineseCalendar; import android.os.Bundle; import androidx.annotation.Nullable; @@ -9,21 +10,17 @@ import android.util.Log; import android.widget.TextView; -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.Miui10Calendar; -import com.necer.entity.CalendarDate; -import com.necer.entity.Lunar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.DateChangeBehavior; import com.necer.enumeration.MultipleCountModel; import com.necer.listener.OnCalendarChangedListener; import com.necer.listener.OnCalendarMultipleChangedListener; import com.necer.ncalendar.R; -import com.necer.painter.CalendarBackground; import com.necer.painter.InnerPainter; -import com.necer.utils.CalendarUtil; +import com.necer.utils.hutool.ChineseDate; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -36,7 +33,7 @@ */ public class TestMiui10Activity extends BaseActivity { - private Miui10Calendar miui10Calendar; + private NCalendar miui10Calendar; private TextView tv_result; private TextView tv_data; @@ -93,17 +90,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + localDate); - Log.d(TAG, " 当前页面选中 " + localDate); - Log.d(TAG, " dateChangeBehavior " + dateChangeBehavior); - - Log.e(TAG, "baseCalendar::" + baseCalendar); if (localDate != null) { - CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate); - Lunar lunar = calendarDate.lunar; - tv_data.setText(localDate.toString("yyyy年MM月dd日")); - tv_desc.setText(lunar.chineseEra + lunar.animals + "年" + lunar.lunarMonthStr + lunar.lunarDayStr); + ChineseDate chineseDate = new ChineseDate(localDate); + tv_data.setText(localDate.toString()); + tv_desc.setText(chineseDate.getChineseZodiac() + chineseDate.getChineseYear() + "年" + chineseDate.getChineseMonth() + chineseDate.getChineseDay()); } else { tv_data.setText(""); tv_desc.setText(""); @@ -113,7 +105,7 @@ public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, Loc }); miui10Calendar.setOnCalendarMultipleChangedListener(new OnCalendarMultipleChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + currPagerCheckedList.size() + "个 总共选中" + totalCheckedList.size() + "个"); Log.d(TAG, year + "年" + month + "月"); Log.d(TAG, "当前页面选中::" + currPagerCheckedList); diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestMiui9Activity.java b/app/src/main/java/com/necer/ncalendar/activity/TestMiui9Activity.java index 721574b3..65b88d8a 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestMiui9Activity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestMiui9Activity.java @@ -8,8 +8,7 @@ import android.view.View; import android.widget.TextView; -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.Miui9Calendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.CalendarState; import com.necer.enumeration.DateChangeBehavior; import com.necer.listener.OnCalendarChangedListener; @@ -18,8 +17,8 @@ import com.necer.ncalendar.R; import com.necer.ncalendar.adapter.RecyclerViewAdapter; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.List; @@ -29,7 +28,7 @@ public class TestMiui9Activity extends BaseActivity { - private Miui9Calendar miui9Calendar; + private NCalendar miui9Calendar; private TextView tv_result; @@ -42,7 +41,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { miui9Calendar = findViewById(R.id.miui9Calendar); - miui9Calendar.setCalendarState(CalendarState.WEEK); miui9Calendar.setCheckMode(checkModel); RecyclerView recyclerView = findViewById(R.id.recyclerView); @@ -53,30 +51,20 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { miui9Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + localDate); - Log.e(TAG, "baseCalendar::" + baseCalendar); } + }); miui9Calendar.setOnCalendarMultipleChangedListener(new OnCalendarMultipleChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + currPagerCheckedList.size() + "个 总共选中" + totalCheckedList.size() + "个"); - Log.d(TAG, year + "年" + month + "月"); - Log.d(TAG, "当前页面选中::" + currPagerCheckedList); - Log.d(TAG, "全部选中::" + totalCheckedList); - Log.e(TAG, "baseCalendar::" + baseCalendar); } - }); - miui9Calendar.setOnCalendarScrollingListener(new OnCalendarScrollingListener() { - @Override - public void onCalendarScrolling(float dy) { - Log.d(TAG, "onCalendarScrolling::" + dy); - } }); } diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestMonthActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestMonthActivity.java index d2a51f68..57f6ea96 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestMonthActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestMonthActivity.java @@ -9,23 +9,21 @@ import android.view.View; import android.widget.TextView; -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.MonthCalendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.DateChangeBehavior; import com.necer.listener.OnCalendarChangedListener; import com.necer.listener.OnCalendarMultipleChangedListener; import com.necer.ncalendar.R; -import com.necer.painter.CalendarBackground; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.List; public class TestMonthActivity extends BaseActivity { private TextView tv_result; - private MonthCalendar monthCalendar; + private NCalendar monthCalendar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -37,30 +35,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { monthCalendar = findViewById(R.id.monthCalendar); monthCalendar.setCheckMode(checkModel); - // monthCalendar.setDefaultSelectFirst(true); - - - monthCalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + localDate); Log.d(TAG, "setOnCalendarChangedListener:::" + year + "年" + month + "月" + " 当前页面选中 " + localDate); - Log.e(TAG, "baseCalendar::" + baseCalendar); } + }); monthCalendar.setOnCalendarMultipleChangedListener(new OnCalendarMultipleChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + currPagerCheckedList.size() + "个 总共选中" + totalCheckedList.size() + "个"); - - Log.d(TAG, year + "年" + month + "月"); - Log.d(TAG, "当前页面选中::" + currPagerCheckedList); - Log.d(TAG, "全部选中::" + totalCheckedList); } }); diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestStretchActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestStretchActivity.java index c7107364..6a600d0f 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestStretchActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestStretchActivity.java @@ -4,7 +4,7 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import com.necer.calendar.Miui10Calendar; +import com.necer.calendar.NCalendar; import com.necer.ncalendar.R; import com.necer.painter.InnerPainter; @@ -16,7 +16,7 @@ public class TestStretchActivity extends AppCompatActivity { - private Miui10Calendar miui10Calendar; + private NCalendar miui10Calendar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -24,7 +24,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_stretch); miui10Calendar = findViewById(R.id.miui10Calendar); - miui10Calendar.setStretchCalendarEnable(true); List pointList = Arrays.asList("2019-07-01", "2019-07-19", "2019-07-25", "2019-05-23", "2019-01-01", "2018-12-23"); @@ -33,12 +32,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { Map strMap = new HashMap<>(); - strMap.put("2019-07-01", "测试"); - strMap.put("2019-07-19", "测试1"); - strMap.put("2019-07-25", "测试2"); - strMap.put("2019-08-25", "测试3"); - strMap.put("2019-08-28", "测试4"); - strMap.put("2019-11-26", "测试5"); + strMap.put("2024-07-01", "测试"); + strMap.put("2024-07-19", "测试1"); + strMap.put("2024-07-25", "测试2"); + strMap.put("2024-08-25", "测试3"); + strMap.put("2024-08-28", "测试4"); + strMap.put("2024-11-26", "测试5"); innerPainter.setStretchStrMap(strMap); } diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestWeekActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestWeekActivity.java index f163edae..8b644763 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestWeekActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestWeekActivity.java @@ -8,22 +8,21 @@ import android.view.View; import android.widget.TextView; -import com.necer.calendar.BaseCalendar; -import com.necer.calendar.WeekCalendar; +import com.necer.calendar.NCalendar; import com.necer.enumeration.DateChangeBehavior; import com.necer.listener.OnCalendarChangedListener; import com.necer.listener.OnCalendarMultipleChangedListener; import com.necer.ncalendar.R; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.List; public class TestWeekActivity extends BaseActivity { private TextView tv_result; - private WeekCalendar weekCalendar; + private NCalendar weekCalendar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -32,23 +31,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { tv_result = findViewById(R.id.tv_result); - weekCalendar = findViewById(R.id.weekCalendar); weekCalendar.setCheckMode(checkModel); weekCalendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + localDate); Log.d(TAG, "setOnCalendarChangedListener:::" + year + "年" + month + "月" + " 当前页面选中 " + localDate); - Log.e(TAG, "baseCalendar::" + baseCalendar); } + }); weekCalendar.setOnCalendarMultipleChangedListener(new OnCalendarMultipleChangedListener() { @Override - public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { + public void onCalendarChange(int year, int month, List currPagerCheckedList, List totalCheckedList, DateChangeBehavior dateChangeBehavior) { tv_result.setText(year + "年" + month + "月" + " 当前页面选中 " + currPagerCheckedList.size() + "个 总共选中" + totalCheckedList.size() + "个"); Log.d(TAG, year + "年" + month + "月"); diff --git a/app/src/main/java/com/necer/ncalendar/activity/TestWeekHoldActivity.java b/app/src/main/java/com/necer/ncalendar/activity/TestWeekHoldActivity.java index 946f0c78..6c13d8a2 100644 --- a/app/src/main/java/com/necer/ncalendar/activity/TestWeekHoldActivity.java +++ b/app/src/main/java/com/necer/ncalendar/activity/TestWeekHoldActivity.java @@ -3,13 +3,14 @@ import android.os.Bundle; import android.os.Handler; import androidx.annotation.Nullable; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + import android.view.View; -import com.necer.calendar.Miui9Calendar; +import com.necer.calendar.NCalendar; import com.necer.ncalendar.R; import com.necer.ncalendar.adapter.RecyclerViewAdapter; @@ -23,7 +24,7 @@ public class TestWeekHoldActivity extends AppCompatActivity { SwipeRefreshLayout refresh_layout; RecyclerView recyclerView; - Miui9Calendar miui9Calendar; + NCalendar miui9Calendar; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { diff --git a/app/src/main/java/com/necer/ncalendar/painter/LigaturePainter.java b/app/src/main/java/com/necer/ncalendar/painter/LigaturePainter.java index a1c78680..981e8559 100644 --- a/app/src/main/java/com/necer/ncalendar/painter/LigaturePainter.java +++ b/app/src/main/java/com/necer/ncalendar/painter/LigaturePainter.java @@ -7,15 +7,12 @@ import android.graphics.RectF; import android.util.TypedValue; -import com.necer.entity.CalendarDate; import com.necer.ncalendar.DensityUtil; import com.necer.painter.CalendarPainter; -import com.necer.utils.CalendarUtil; -import com.necer.view.CalendarView; -import com.necer.view.ICalendarView; - -import org.joda.time.LocalDate; +import com.necer.utils.NDateUtil; +import com.necer.utils.hutool.ChineseDate; +import java.time.LocalDate; import java.util.List; /** @@ -81,16 +78,16 @@ private void drawSelectBg(Canvas canvas, RectF rectF, LocalDate localDate, boole LocalDate nextLocalDate = localDate.plusDays(1); if (selectedDateList.contains(localDate)) { - if (selectedDateList.contains(lastLocalDate) && selectedDateList.contains(nextLocalDate) && CalendarUtil.isEqualsMonth(lastLocalDate, nextLocalDate)) { + if (selectedDateList.contains(lastLocalDate) && selectedDateList.contains(nextLocalDate) && NDateUtil.INSTANCE.isEqualsMonth(lastLocalDate, nextLocalDate)) { //画全整个矩形 - RectF rectF1 = new RectF(rectF.left, rectF.centerY() - mCircleRadius, rectF.right, rectF.centerY() + mCircleRadius); + RectF rectF1 = new RectF(rectF.left - 1f, rectF.centerY() - mCircleRadius, rectF.right + 1f, rectF.centerY() + mCircleRadius); mBgPaint.setAntiAlias(false); mBgPaint.setStyle(Paint.Style.FILL_AND_STROKE); canvas.drawRect(rectF1, mBgPaint); - } else if (selectedDateList.contains(lastLocalDate) && (!selectedDateList.contains(nextLocalDate) || !CalendarUtil.isEqualsMonth(nextLocalDate, localDate)) && CalendarUtil.isEqualsMonth(lastLocalDate, localDate)) { + } else if (selectedDateList.contains(lastLocalDate) && (!selectedDateList.contains(nextLocalDate) || !NDateUtil.INSTANCE.isEqualsMonth(nextLocalDate, localDate)) && NDateUtil.INSTANCE.isEqualsMonth(lastLocalDate, localDate)) { //左矩形 右圆 - RectF rectF1 = new RectF(rectF.left, rectF.centerY() - mCircleRadius, rectF.centerX(), rectF.centerY() + mCircleRadius); + RectF rectF1 = new RectF(rectF.left- 1f, rectF.centerY() - mCircleRadius, rectF.centerX(), rectF.centerY() + mCircleRadius); mBgPaint.setAntiAlias(false); mBgPaint.setStyle(Paint.Style.FILL_AND_STROKE); canvas.drawRect(rectF1, mBgPaint); @@ -104,9 +101,9 @@ private void drawSelectBg(Canvas canvas, RectF rectF, LocalDate localDate, boole mBgPaint.setStyle(Paint.Style.STROKE); canvas.drawArc(rectF2, -90, 180, false, mBgPaint);//右半圆弧 - } else if ((!selectedDateList.contains(lastLocalDate) || !CalendarUtil.isEqualsMonth(lastLocalDate, localDate)) && selectedDateList.contains(nextLocalDate) && CalendarUtil.isEqualsMonth(nextLocalDate, localDate)) { + } else if ((!selectedDateList.contains(lastLocalDate) || !NDateUtil.INSTANCE.isEqualsMonth(lastLocalDate, localDate)) && selectedDateList.contains(nextLocalDate) && NDateUtil.INSTANCE.isEqualsMonth(nextLocalDate, localDate)) { //右矩形 左圆 - RectF rectF1 = new RectF(rectF.centerX(), rectF.centerY() - mCircleRadius, rectF.right, rectF.centerY() + mCircleRadius); + RectF rectF1 = new RectF(rectF.centerX(), rectF.centerY() - mCircleRadius, rectF.right+1f, rectF.centerY() + mCircleRadius); mBgPaint.setAntiAlias(false); mBgPaint.setStyle(Paint.Style.FILL_AND_STROKE); canvas.drawRect(rectF1, mBgPaint); @@ -140,10 +137,10 @@ private void drawSolar(Canvas canvas, RectF rectF, LocalDate date, boolean isSel //绘制农历 private void drawLunar(Canvas canvas, RectF rectF, LocalDate date, boolean isSelected, boolean isCurrectMonthOrWeek) { mTextPaint.setTextSize(DensityUtil.dp2px(mContext, 10)); - CalendarDate calendarDate = CalendarUtil.getCalendarDate(date); + ChineseDate chineseDate = new ChineseDate(date); mTextPaint.setColor(isSelected ? Color.WHITE : Color.GRAY); mTextPaint.setAlpha(isCurrectMonthOrWeek ? 255 : 100); - canvas.drawText(calendarDate.lunar.lunarOnDrawStr, rectF.centerX(), rectF.centerY() + DensityUtil.dp2px(mContext, 12), mTextPaint); + canvas.drawText(chineseDate.getChineseMonthName(), rectF.centerX(), rectF.centerY() + DensityUtil.dp2px(mContext, 12), mTextPaint); } diff --git a/app/src/main/java/com/necer/ncalendar/painter/StretchPainter.java b/app/src/main/java/com/necer/ncalendar/painter/StretchPainter.java index b729ede9..d308fe84 100644 --- a/app/src/main/java/com/necer/ncalendar/painter/StretchPainter.java +++ b/app/src/main/java/com/necer/ncalendar/painter/StretchPainter.java @@ -9,12 +9,9 @@ import com.necer.ncalendar.DensityUtil; import com.necer.painter.CalendarPainter; -import com.necer.utils.CalendarUtil; -import com.necer.view.CalendarView; -import com.necer.view.ICalendarView; -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.List; public class StretchPainter implements CalendarPainter { diff --git a/app/src/main/java/com/necer/ncalendar/painter/TicketPainter.java b/app/src/main/java/com/necer/ncalendar/painter/TicketPainter.java index e365a054..31718865 100644 --- a/app/src/main/java/com/necer/ncalendar/painter/TicketPainter.java +++ b/app/src/main/java/com/necer/ncalendar/painter/TicketPainter.java @@ -10,12 +10,8 @@ import com.necer.calendar.ICalendar; import com.necer.ncalendar.DensityUtil; import com.necer.painter.CalendarPainter; -import com.necer.utils.CalendarUtil; -import com.necer.view.CalendarView; -import com.necer.view.ICalendarView; - -import org.joda.time.LocalDate; +import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -52,14 +48,14 @@ public TicketPainter(Context context, ICalendar iCalendar) { mHolidayList = new ArrayList<>(); mWorkdayList = new ArrayList<>(); - List holidayList = CalendarUtil.getHolidayList(); - for (int i = 0; i < holidayList.size(); i++) { - mHolidayList.add(new LocalDate(holidayList.get(i))); - } - List workdayList = CalendarUtil.getWorkdayList(); - for (int i = 0; i < workdayList.size(); i++) { - mWorkdayList.add(new LocalDate(workdayList.get(i))); - } +// List holidayList = CalendarUtil.getHolidayList(); +// for (int i = 0; i < holidayList.size(); i++) { +// mHolidayList.add(new LocalDate(holidayList.get(i))); +// } +// List workdayList = CalendarUtil.getWorkdayList(); +// for (int i = 0; i < workdayList.size(); i++) { +// mWorkdayList.add(new LocalDate(workdayList.get(i))); +// } } diff --git a/app/src/main/res/layout/activity_adapter.xml b/app/src/main/res/layout/activity_adapter.xml index ce3f4e22..3abb346f 100644 --- a/app/src/main/res/layout/activity_adapter.xml +++ b/app/src/main/res/layout/activity_adapter.xml @@ -6,13 +6,8 @@ android:orientation="vertical"> - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_add_view.xml b/app/src/main/res/layout/activity_add_view.xml index f8a10dfe..72e3368f 100644 --- a/app/src/main/res/layout/activity_add_view.xml +++ b/app/src/main/res/layout/activity_add_view.xml @@ -6,13 +6,7 @@ android:orientation="vertical"> - - - @@ -62,5 +56,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_custom.xml b/app/src/main/res/layout/activity_custom.xml index bb85b407..c75f23b4 100644 --- a/app/src/main/res/layout/activity_custom.xml +++ b/app/src/main/res/layout/activity_custom.xml @@ -25,13 +25,8 @@ - - - @@ -58,7 +53,7 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_emui.xml b/app/src/main/res/layout/activity_emui.xml index 0310b682..e4ca5a5d 100644 --- a/app/src/main/res/layout/activity_emui.xml +++ b/app/src/main/res/layout/activity_emui.xml @@ -61,12 +61,8 @@ - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_general.xml b/app/src/main/res/layout/activity_general.xml index 4d483ceb..3f7bb9a5 100644 --- a/app/src/main/res/layout/activity_general.xml +++ b/app/src/main/res/layout/activity_general.xml @@ -5,11 +5,8 @@ android:orientation="vertical"> - - @@ -24,7 +21,7 @@ android:background="@color/colorAccent" android:text="我只是一个TextView" /> - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 3da51b0a..7b218d6d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -77,21 +77,21 @@ android:layout_height="wrap_content" android:layout_weight="1" android:onClick="miui9_selected" - android:text="miui9选中" /> + android:text="日历1选中" />