├── .classpath
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── Calendar.png
├── README.md
├── bin
├── AndroidManifest.xml
├── Calendar.apk
├── Clander.apk
├── classes.dex
├── classes
│ └── com
│ │ └── example
│ │ └── calendar
│ │ ├── BuildConfig.class
│ │ ├── CalendarActivity$1.class
│ │ ├── CalendarActivity$2.class
│ │ ├── CalendarActivity$MyGestureListener.class
│ │ ├── CalendarActivity.class
│ │ ├── CalendarAdapter.class
│ │ ├── LunarCalendar.class
│ │ ├── R$anim.class
│ │ ├── R$attr.class
│ │ ├── R$color.class
│ │ ├── R$dimen.class
│ │ ├── R$drawable.class
│ │ ├── R$id.class
│ │ ├── R$layout.class
│ │ ├── R$menu.class
│ │ ├── R$string.class
│ │ ├── R$style.class
│ │ ├── R.class
│ │ └── SpecialCalendar.class
├── dexedLibs
│ ├── android-support-v4-196c466b5402d9cc6694427381924ac4.jar
│ ├── android-support-v4-2ac2e775b899d08d10544100df942b79.jar
│ └── android-support-v4-421bec67abbce98c420036a4757d2432.jar
├── jarlist.cache
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ ├── btn_bg_normal.9.png
│ │ ├── btn_bg_press.9.png
│ │ ├── calendar_item_selected_bg.png
│ │ ├── current_day_bgc.png
│ │ ├── ic_launcher.png
│ │ ├── mark.png
│ │ ├── next_month.png
│ │ ├── prev_month.png
│ │ ├── title_bg.png
│ │ ├── triangle05.png
│ │ ├── triangle05_pressed.png
│ │ ├── triangle06.png
│ │ └── triangle06_pressed.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ └── drawable-xxhdpi
│ │ └── ic_launcher.png
└── resources.ap_
├── gen
└── com
│ └── example
│ └── calendar
│ ├── BuildConfig.java
│ └── R.java
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── proguard-project.txt
├── project.properties
├── res
├── anim
│ ├── push_left_in.xml
│ ├── push_left_out.xml
│ ├── push_right_in.xml
│ └── push_right_out.xml
├── drawable-hdpi
│ ├── btn_bg_normal.9.png
│ ├── btn_bg_press.9.png
│ ├── calendar_item_selected_bg.png
│ ├── current_day_bgc.png
│ ├── ic_launcher.png
│ ├── mark.png
│ ├── next_month.png
│ ├── prev_month.png
│ ├── title_bg.png
│ ├── triangle05.png
│ ├── triangle05_pressed.png
│ ├── triangle06.png
│ └── triangle06_pressed.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── defselector.xml
│ ├── triangle05_states.xml
│ └── triangle06_states.xml
├── layout
│ ├── calendar.xml
│ ├── calendar_gridview.xml
│ └── calendar_item.xml
├── menu
│ └── main.xml
├── values-sw600dp
│ └── dimens.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── calendar
├── CalendarActivity.java
├── CalendarAdapter.java
├── LunarCalendar.java
└── SpecialCalendar.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Calendar
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/com/example/calendar/CalendarActivity.java=UTF-8
3 | encoding/=UTF-8
4 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Calendar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/Calendar.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Calendar
2 | ========
3 |
4 | 这是一个符合中国人使用习惯的Android上自定义日历控件。
5 |
6 | 该日历集成公历农历显示、节假日和二十四节气的显示。代码小巧玲珑,易于项目整合。提供农历算法、闰年月算法。
7 | 日历本身为动态代码生成的6*7的GridView,结合ViewFlipper完成日历的滑动切换功能。
8 | 
9 |
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/bin/Calendar.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/Calendar.apk
--------------------------------------------------------------------------------
/bin/Clander.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/Clander.apk
--------------------------------------------------------------------------------
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes.dex
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/BuildConfig.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/CalendarActivity$1.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/CalendarActivity$1.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/CalendarActivity$2.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/CalendarActivity$2.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/CalendarActivity$MyGestureListener.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/CalendarActivity$MyGestureListener.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/CalendarActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/CalendarActivity.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/CalendarAdapter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/CalendarAdapter.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/LunarCalendar.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/LunarCalendar.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$anim.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$anim.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$attr.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$color.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$color.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$dimen.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$drawable.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$id.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$layout.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$menu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$menu.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$string.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R$style.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/R.class
--------------------------------------------------------------------------------
/bin/classes/com/example/calendar/SpecialCalendar.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/classes/com/example/calendar/SpecialCalendar.class
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-196c466b5402d9cc6694427381924ac4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/dexedLibs/android-support-v4-196c466b5402d9cc6694427381924ac4.jar
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-2ac2e775b899d08d10544100df942b79.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/dexedLibs/android-support-v4-2ac2e775b899d08d10544100df942b79.jar
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-421bec67abbce98c420036a4757d2432.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/dexedLibs/android-support-v4-421bec67abbce98c420036a4757d2432.jar
--------------------------------------------------------------------------------
/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/btn_bg_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/btn_bg_normal.9.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/btn_bg_press.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/btn_bg_press.9.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/calendar_item_selected_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/calendar_item_selected_bg.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/current_day_bgc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/current_day_bgc.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/mark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/mark.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/next_month.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/next_month.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/prev_month.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/prev_month.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/title_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/title_bg.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/triangle05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/triangle05.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/triangle05_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/triangle05_pressed.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/triangle06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/triangle06.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/triangle06_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-hdpi/triangle06_pressed.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/bin/resources.ap_
--------------------------------------------------------------------------------
/gen/com/example/calendar/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.calendar;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/gen/com/example/calendar/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.calendar;
9 |
10 | public final class R {
11 | public static final class anim {
12 | public static final int push_left_in=0x7f040000;
13 | public static final int push_left_out=0x7f040001;
14 | public static final int push_right_in=0x7f040002;
15 | public static final int push_right_out=0x7f040003;
16 | }
17 | public static final class attr {
18 | }
19 | public static final class color {
20 | /** A really bright Holo shade of blue
21 | */
22 | public static final int holo_blue_bright=0x7f05000b;
23 | /** A dark Holo shade of blue
24 | */
25 | public static final int holo_blue_dark=0x7f050005;
26 | /** A light Holo shade of blue
27 | */
28 | public static final int holo_blue_light=0x7f050002;
29 | /** A dark Holo shade of green
30 | */
31 | public static final int holo_green_dark=0x7f050006;
32 | /** A light Holo shade of green
33 | */
34 | public static final int holo_green_light=0x7f050003;
35 | /** A dark Holo shade of orange
36 | */
37 | public static final int holo_orange_dark=0x7f05000a;
38 | /** A light Holo shade of orange
39 | */
40 | public static final int holo_orange_light=0x7f050009;
41 | /** A Holo shade of purple
42 | */
43 | public static final int holo_purple=0x7f050008;
44 | /** A dark Holo shade of red
45 | */
46 | public static final int holo_red_dark=0x7f050007;
47 | /** A light Holo shade of red
48 | */
49 | public static final int holo_red_light=0x7f050004;
50 | /** menudraw
51 | */
52 | public static final int md__defaultBackground=0x7f050001;
53 | /**
54 | */
55 | public static final int msg_emote_divider=0x7f050000;
56 | }
57 | public static final class dimen {
58 | /** Default screen margins, per the Android Design guidelines.
59 |
60 | Customize dimensions originally defined in res/values/dimens.xml (such as
61 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
62 |
63 | */
64 | public static final int activity_horizontal_margin=0x7f060000;
65 | public static final int activity_vertical_margin=0x7f060001;
66 | }
67 | public static final class drawable {
68 | public static final int btn_bg_normal=0x7f020000;
69 | public static final int btn_bg_press=0x7f020001;
70 | public static final int calendar_item_selected_bg=0x7f020002;
71 | public static final int current_day_bgc=0x7f020003;
72 | public static final int defselector=0x7f020004;
73 | public static final int ic_launcher=0x7f020005;
74 | public static final int mark=0x7f020006;
75 | public static final int next_month=0x7f020007;
76 | public static final int prev_month=0x7f020008;
77 | public static final int title_bg=0x7f020009;
78 | public static final int triangle05=0x7f02000a;
79 | public static final int triangle05_pressed=0x7f02000b;
80 | public static final int triangle05_states=0x7f02000c;
81 | public static final int triangle06=0x7f02000d;
82 | public static final int triangle06_pressed=0x7f02000e;
83 | public static final int triangle06_states=0x7f02000f;
84 | }
85 | public static final class id {
86 | public static final int action_settings=0x7f0a0006;
87 | public static final int currentMonth=0x7f0a0001;
88 | public static final int flipper=0x7f0a0003;
89 | public static final int gv_calendar=0x7f0a0004;
90 | public static final int nextMonth=0x7f0a0002;
91 | public static final int prevMonth=0x7f0a0000;
92 | public static final int tvtext=0x7f0a0005;
93 | }
94 | public static final class layout {
95 | public static final int calendar=0x7f030000;
96 | public static final int calendar_gridview=0x7f030001;
97 | public static final int calendar_item=0x7f030002;
98 | }
99 | public static final class menu {
100 | public static final int main=0x7f090000;
101 | }
102 | public static final class string {
103 | public static final int action_settings=0x7f070001;
104 | public static final int app_name=0x7f070000;
105 | public static final int hello_world=0x7f070002;
106 | }
107 | public static final class style {
108 | /**
109 | Base application theme, dependent on API level. This theme is replaced
110 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
111 |
112 |
113 |
114 | Theme customizations available in newer API levels can go in
115 | res/values-vXX/styles.xml, while customizations related to
116 | backward-compatibility can go here.
117 |
118 |
119 |
120 | Base application theme for API 11+. This theme completely replaces
121 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
122 |
123 | API 11 theme customizations can go here.
124 |
125 | Base application theme for API 14+. This theme completely replaces
126 | AppBaseTheme from BOTH res/values/styles.xml and
127 | res/values-v11/styles.xml on API 14+ devices.
128 |
129 | API 14 theme customizations can go here.
130 | */
131 | public static final int AppBaseTheme=0x7f080000;
132 | /** Application theme.
133 | */
134 | public static final int AppTheme=0x7f080001;
135 | public static final int weekName=0x7f080002;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-18
15 |
--------------------------------------------------------------------------------
/res/anim/push_left_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/res/anim/push_left_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/res/anim/push_right_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
--------------------------------------------------------------------------------
/res/anim/push_right_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 |
7 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/btn_bg_normal.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/btn_bg_normal.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/btn_bg_press.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/btn_bg_press.9.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/calendar_item_selected_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/calendar_item_selected_bg.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/current_day_bgc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/current_day_bgc.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/mark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/mark.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/next_month.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/next_month.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/prev_month.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/prev_month.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/title_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/title_bg.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/triangle05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/triangle05.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/triangle05_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/triangle05_pressed.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/triangle06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/triangle06.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/triangle06_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-hdpi/triangle06_pressed.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lichao315/Calendar/bb5f4dc2e3cfa660505c2105ca66d0f6873cbf2f/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/defselector.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/drawable/triangle05_states.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/res/drawable/triangle06_states.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/res/layout/calendar.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
19 |
20 |
29 |
30 |
37 |
38 |
39 |
43 |
44 |
48 |
49 |
52 |
53 |
56 |
57 |
60 |
61 |
64 |
65 |
68 |
69 |
73 |
74 |
75 |
79 |
80 |
84 |
85 |
--------------------------------------------------------------------------------
/res/layout/calendar_gridview.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
21 |
22 |
--------------------------------------------------------------------------------
/res/layout/calendar_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #ffa1a1a1
5 |
6 | #FF555555
7 |
8 |
9 | #ff33b5e5
10 |
11 | #ff99cc00
12 |
13 | #ffff4444
14 |
15 | #ff0099cc
16 |
17 | #ff669900
18 |
19 | #ffcc0000
20 |
21 | #ffaa66cc
22 |
23 | #ffffbb33
24 |
25 | #ffff8800
26 |
27 | #ff00ddff
28 |
29 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Clander
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
21 |
22 |
31 |
32 |
--------------------------------------------------------------------------------
/src/com/example/calendar/CalendarActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.calendar;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 |
6 | import android.app.Activity;
7 | import android.graphics.Color;
8 | import android.graphics.drawable.ColorDrawable;
9 | import android.os.Bundle;
10 | import android.view.Display;
11 | import android.view.GestureDetector;
12 | import android.view.GestureDetector.SimpleOnGestureListener;
13 | import android.view.Gravity;
14 | import android.view.MotionEvent;
15 | import android.view.View;
16 | import android.view.View.OnTouchListener;
17 | import android.view.WindowManager;
18 | import android.view.animation.AnimationUtils;
19 | import android.widget.AbsListView.LayoutParams;
20 | import android.widget.AdapterView;
21 | import android.widget.AdapterView.OnItemClickListener;
22 | import android.widget.GridView;
23 | import android.widget.ImageView;
24 | import android.widget.LinearLayout;
25 | import android.widget.TextView;
26 | import android.widget.Toast;
27 | import android.widget.ViewFlipper;
28 |
29 | /**
30 | * 日历显示activity
31 | *
32 | * @author Vincent Lee
33 | *
34 | */
35 | public class CalendarActivity extends Activity implements View.OnClickListener {
36 |
37 | private GestureDetector gestureDetector = null;
38 | private CalendarAdapter calV = null;
39 | private ViewFlipper flipper = null;
40 | private GridView gridView = null;
41 | private static int jumpMonth = 0; // 每次滑动,增加或减去一个月,默认为0(即显示当前月)
42 | private static int jumpYear = 0; // 滑动跨越一年,则增加或者减去一年,默认为0(即当前年)
43 | private int year_c = 0;
44 | private int month_c = 0;
45 | private int day_c = 0;
46 | private String currentDate = "";
47 | /** 每次添加gridview到viewflipper中时给的标记 */
48 | private int gvFlag = 0;
49 | /** 当前的年月,现在日历顶端 */
50 | private TextView currentMonth;
51 | /** 上个月 */
52 | private ImageView prevMonth;
53 | /** 下个月 */
54 | private ImageView nextMonth;
55 |
56 | public CalendarActivity() {
57 |
58 | Date date = new Date();
59 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
60 | currentDate = sdf.format(date); // 当期日期
61 | year_c = Integer.parseInt(currentDate.split("-")[0]);
62 | month_c = Integer.parseInt(currentDate.split("-")[1]);
63 | day_c = Integer.parseInt(currentDate.split("-")[2]);
64 |
65 | }
66 |
67 | @Override
68 | public void onCreate(Bundle savedInstanceState) {
69 | super.onCreate(savedInstanceState);
70 | setContentView(R.layout.calendar);
71 | currentMonth = (TextView) findViewById(R.id.currentMonth);
72 | prevMonth = (ImageView) findViewById(R.id.prevMonth);
73 | nextMonth = (ImageView) findViewById(R.id.nextMonth);
74 | setListener();
75 |
76 | gestureDetector = new GestureDetector(this, new MyGestureListener());
77 | flipper = (ViewFlipper) findViewById(R.id.flipper);
78 | flipper.removeAllViews();
79 | calV = new CalendarAdapter(this, getResources(), jumpMonth, jumpYear, year_c, month_c, day_c);
80 | addGridView();
81 | gridView.setAdapter(calV);
82 | flipper.addView(gridView, 0);
83 | addTextToTopTextView(currentMonth);
84 | }
85 |
86 | private class MyGestureListener extends SimpleOnGestureListener {
87 | @Override
88 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
89 | int gvFlag = 0; // 每次添加gridview到viewflipper中时给的标记
90 | if (e1.getX() - e2.getX() > 120) {
91 | // 像左滑动
92 | enterNextMonth(gvFlag);
93 | return true;
94 | } else if (e1.getX() - e2.getX() < -120) {
95 | // 向右滑动
96 | enterPrevMonth(gvFlag);
97 | return true;
98 | }
99 | return false;
100 | }
101 | }
102 |
103 | /**
104 | * 移动到下一个月
105 | *
106 | * @param gvFlag
107 | */
108 | private void enterNextMonth(int gvFlag) {
109 | addGridView(); // 添加一个gridView
110 | jumpMonth++; // 下一个月
111 |
112 | calV = new CalendarAdapter(this, this.getResources(), jumpMonth, jumpYear, year_c, month_c, day_c);
113 | gridView.setAdapter(calV);
114 | addTextToTopTextView(currentMonth); // 移动到下一月后,将当月显示在头标题中
115 | gvFlag++;
116 | flipper.addView(gridView, gvFlag);
117 | flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
118 | flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
119 | flipper.showNext();
120 | flipper.removeViewAt(0);
121 | }
122 |
123 | /**
124 | * 移动到上一个月
125 | *
126 | * @param gvFlag
127 | */
128 | private void enterPrevMonth(int gvFlag) {
129 | addGridView(); // 添加一个gridView
130 | jumpMonth--; // 上一个月
131 |
132 | calV = new CalendarAdapter(this, this.getResources(), jumpMonth, jumpYear, year_c, month_c, day_c);
133 | gridView.setAdapter(calV);
134 | gvFlag++;
135 | addTextToTopTextView(currentMonth); // 移动到上一月后,将当月显示在头标题中
136 | flipper.addView(gridView, gvFlag);
137 |
138 | flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
139 | flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
140 | flipper.showPrevious();
141 | flipper.removeViewAt(0);
142 | }
143 |
144 | /**
145 | * 添加头部的年份 闰哪月等信息
146 | *
147 | * @param view
148 | */
149 | public void addTextToTopTextView(TextView view) {
150 | StringBuffer textDate = new StringBuffer();
151 | // draw = getResources().getDrawable(R.drawable.top_day);
152 | // view.setBackgroundDrawable(draw);
153 | textDate.append(calV.getShowYear()).append("年").append(calV.getShowMonth()).append("月").append("\t");
154 | view.setText(textDate);
155 | }
156 |
157 | private void addGridView() {
158 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
159 | // 取得屏幕的宽度和高度
160 | WindowManager windowManager = getWindowManager();
161 | Display display = windowManager.getDefaultDisplay();
162 | int Width = display.getWidth();
163 | int Height = display.getHeight();
164 |
165 | gridView = new GridView(this);
166 | gridView.setNumColumns(7);
167 | gridView.setColumnWidth(40);
168 | // gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
169 | if (Width == 720 && Height == 1280) {
170 | gridView.setColumnWidth(40);
171 | }
172 | gridView.setGravity(Gravity.CENTER_VERTICAL);
173 | gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
174 | // 去除gridView边框
175 | gridView.setVerticalSpacing(1);
176 | gridView.setHorizontalSpacing(1);
177 | gridView.setOnTouchListener(new OnTouchListener() {
178 | // 将gridview中的触摸事件回传给gestureDetector
179 |
180 | public boolean onTouch(View v, MotionEvent event) {
181 | // TODO Auto-generated method stub
182 | return CalendarActivity.this.gestureDetector.onTouchEvent(event);
183 | }
184 | });
185 |
186 | gridView.setOnItemClickListener(new OnItemClickListener() {
187 |
188 | @Override
189 | public void onItemClick(AdapterView> arg0, View arg1, int position, long arg3) {
190 | // TODO Auto-generated method stub
191 | // 点击任何一个item,得到这个item的日期(排除点击的是周日到周六(点击不响应))
192 | int startPosition = calV.getStartPositon();
193 | int endPosition = calV.getEndPosition();
194 | if (startPosition <= position + 7 && position <= endPosition - 7) {
195 | String scheduleDay = calV.getDateByClickItem(position).split("\\.")[0]; // 这一天的阳历
196 | // String scheduleLunarDay =
197 | // calV.getDateByClickItem(position).split("\\.")[1];
198 | // //这一天的阴历
199 | String scheduleYear = calV.getShowYear();
200 | String scheduleMonth = calV.getShowMonth();
201 | Toast.makeText(CalendarActivity.this, scheduleYear + "-" + scheduleMonth + "-" + scheduleDay, 2000).show();
202 | // Toast.makeText(CalendarActivity.this, "点击了该条目",
203 | // Toast.LENGTH_SHORT).show();
204 | }
205 | }
206 | });
207 | gridView.setLayoutParams(params);
208 | }
209 |
210 | private void setListener() {
211 | prevMonth.setOnClickListener(this);
212 | nextMonth.setOnClickListener(this);
213 | }
214 |
215 | @Override
216 | public void onClick(View v) {
217 | // TODO Auto-generated method stub
218 | switch (v.getId()) {
219 | case R.id.nextMonth: // 下一个月
220 | enterNextMonth(gvFlag);
221 | break;
222 | case R.id.prevMonth: // 上一个月
223 | enterPrevMonth(gvFlag);
224 | break;
225 | default:
226 | break;
227 | }
228 | }
229 |
230 | }
--------------------------------------------------------------------------------
/src/com/example/calendar/CalendarAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.calendar;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Date;
5 |
6 | import android.content.Context;
7 | import android.content.res.Resources;
8 | import android.graphics.Color;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.graphics.drawable.Drawable;
11 | import android.text.SpannableString;
12 | import android.text.Spanned;
13 | import android.text.style.RelativeSizeSpan;
14 | import android.text.style.StyleSpan;
15 | import android.util.Log;
16 | import android.view.LayoutInflater;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.widget.BaseAdapter;
20 | import android.widget.TextView;
21 |
22 | /**
23 | * 日历gridview中的每一个item显示的textview
24 | *
25 | * @author Vincent Lee
26 | *
27 | */
28 | public class CalendarAdapter extends BaseAdapter {
29 | private boolean isLeapyear = false; // 是否为闰年
30 | private int daysOfMonth = 0; // 某月的天数
31 | private int dayOfWeek = 0; // 具体某一天是星期几
32 | private int lastDaysOfMonth = 0; // 上一个月的总天数
33 | private Context context;
34 | private String[] dayNumber = new String[42]; // 一个gridview中的日期存入此数组中
35 | // private static String week[] = {"周日","周一","周二","周三","周四","周五","周六"};
36 | private SpecialCalendar sc = null;
37 | private LunarCalendar lc = null;
38 | private Resources res = null;
39 | private Drawable drawable = null;
40 |
41 | private String currentYear = "";
42 | private String currentMonth = "";
43 | private String currentDay = "";
44 |
45 | private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
46 | private int currentFlag = -1; // 用于标记当天
47 | private int[] schDateTagFlag = null; // 存储当月所有的日程日期
48 |
49 | private String showYear = ""; // 用于在头部显示的年份
50 | private String showMonth = ""; // 用于在头部显示的月份
51 | private String animalsYear = "";
52 | private String leapMonth = ""; // 闰哪一个月
53 | private String cyclical = ""; // 天干地支
54 | // 系统当前时间
55 | private String sysDate = "";
56 | private String sys_year = "";
57 | private String sys_month = "";
58 | private String sys_day = "";
59 |
60 | public CalendarAdapter() {
61 | Date date = new Date();
62 | sysDate = sdf.format(date); // 当期日期
63 | sys_year = sysDate.split("-")[0];
64 | sys_month = sysDate.split("-")[1];
65 | sys_day = sysDate.split("-")[2];
66 |
67 | }
68 |
69 | public CalendarAdapter(Context context, Resources rs, int jumpMonth, int jumpYear, int year_c, int month_c, int day_c) {
70 | this();
71 | this.context = context;
72 | sc = new SpecialCalendar();
73 | lc = new LunarCalendar();
74 | this.res = rs;
75 |
76 | int stepYear = year_c + jumpYear;
77 | int stepMonth = month_c + jumpMonth;
78 | if (stepMonth > 0) {
79 | // 往下一个月滑动
80 | if (stepMonth % 12 == 0) {
81 | stepYear = year_c + stepMonth / 12 - 1;
82 | stepMonth = 12;
83 | } else {
84 | stepYear = year_c + stepMonth / 12;
85 | stepMonth = stepMonth % 12;
86 | }
87 | } else {
88 | // 往上一个月滑动
89 | stepYear = year_c - 1 + stepMonth / 12;
90 | stepMonth = stepMonth % 12 + 12;
91 | if (stepMonth % 12 == 0) {
92 |
93 | }
94 | }
95 |
96 | currentYear = String.valueOf(stepYear); // 得到当前的年份
97 | currentMonth = String.valueOf(stepMonth); // 得到本月
98 | // (jumpMonth为滑动的次数,每滑动一次就增加一月或减一月)
99 | currentDay = String.valueOf(day_c); // 得到当前日期是哪天
100 |
101 | getCalendar(Integer.parseInt(currentYear), Integer.parseInt(currentMonth));
102 |
103 | }
104 |
105 | public CalendarAdapter(Context context, Resources rs, int year, int month, int day) {
106 | this();
107 | this.context = context;
108 | sc = new SpecialCalendar();
109 | lc = new LunarCalendar();
110 | this.res = rs;
111 | currentYear = String.valueOf(year);// 得到跳转到的年份
112 | currentMonth = String.valueOf(month); // 得到跳转到的月份
113 | currentDay = String.valueOf(day); // 得到跳转到的天
114 | getCalendar(Integer.parseInt(currentYear), Integer.parseInt(currentMonth));
115 | }
116 |
117 | @Override
118 | public int getCount() {
119 | // TODO Auto-generated method stub
120 | return dayNumber.length;
121 | }
122 |
123 | @Override
124 | public Object getItem(int position) {
125 | // TODO Auto-generated method stub
126 | return position;
127 | }
128 |
129 | @Override
130 | public long getItemId(int position) {
131 | // TODO Auto-generated method stub
132 | return position;
133 | }
134 |
135 | @Override
136 | public View getView(int position, View convertView, ViewGroup parent) {
137 |
138 | if (convertView == null) {
139 | convertView = LayoutInflater.from(context).inflate(R.layout.calendar_item, null);
140 | }
141 | TextView textView = (TextView) convertView.findViewById(R.id.tvtext);
142 | String d = dayNumber[position].split("\\.")[0];
143 | String dv = dayNumber[position].split("\\.")[1];
144 |
145 | SpannableString sp = new SpannableString(d + "\n" + dv);
146 | sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, d.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
147 | sp.setSpan(new RelativeSizeSpan(1.2f), 0, d.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
148 | if (dv != null || dv != "") {
149 | sp.setSpan(new RelativeSizeSpan(0.75f), d.length() + 1, dayNumber[position].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
150 | }
151 | // sp.setSpan(new ForegroundColorSpan(Color.MAGENTA), 14, 16,
152 | // Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
153 | textView.setText(sp);
154 | textView.setTextColor(Color.GRAY);
155 |
156 | if (position < daysOfMonth + dayOfWeek && position >= dayOfWeek) {
157 | // 当前月信息显示
158 | textView.setTextColor(Color.BLACK);// 当月字体设黑
159 | // drawable = res.getDrawable(R.drawable.calendar_item_selected_bg);
160 | drawable = new ColorDrawable(Color.rgb(23, 126, 214));
161 | if (position % 7 == 0 || position % 7 == 6) {
162 | // 当前月信息显示
163 | textView.setTextColor(Color.rgb(23, 126, 214));// 当月字体设黑
164 | // drawable = res.getDrawable(R.drawable.calendar_item_selected_bg);
165 | drawable = new ColorDrawable(Color.rgb(23, 126, 214));
166 | }
167 | }
168 |
169 | if (currentFlag == position) {
170 | // 设置当天的背景
171 | // drawable = res.getDrawable(R.drawable.calendar_item_selected_bg);
172 | drawable = new ColorDrawable(Color.rgb(23, 126, 214));
173 | textView.setBackgroundDrawable(drawable);
174 | textView.setTextColor(Color.WHITE);
175 | }
176 | return convertView;
177 | }
178 |
179 | // 得到某年的某月的天数且这月的第一天是星期几
180 | public void getCalendar(int year, int month) {
181 | isLeapyear = sc.isLeapYear(year); // 是否为闰年
182 | daysOfMonth = sc.getDaysOfMonth(isLeapyear, month); // 某月的总天数
183 | dayOfWeek = sc.getWeekdayOfMonth(year, month); // 某月第一天为星期几
184 | lastDaysOfMonth = sc.getDaysOfMonth(isLeapyear, month - 1); // 上一个月的总天数
185 | Log.d("DAY", isLeapyear + " ====== " + daysOfMonth + " ============ " + dayOfWeek + " ========= " + lastDaysOfMonth);
186 | getweek(year, month);
187 | }
188 |
189 | // 将一个月中的每一天的值添加入数组dayNuber中
190 | private void getweek(int year, int month) {
191 | int j = 1;
192 | int flag = 0;
193 | String lunarDay = "";
194 |
195 | // 得到当前月的所有日程日期(这些日期需要标记)
196 |
197 | for (int i = 0; i < dayNumber.length; i++) {
198 | // 周一
199 | // if(i<7){
200 | // dayNumber[i]=week[i]+"."+" ";
201 | // }
202 | if (i < dayOfWeek) { // 前一个月
203 | int temp = lastDaysOfMonth - dayOfWeek + 1;
204 | lunarDay = lc.getLunarDate(year, month - 1, temp + i, false);
205 | dayNumber[i] = (temp + i) + "." + lunarDay;
206 |
207 | } else if (i < daysOfMonth + dayOfWeek) { // 本月
208 | String day = String.valueOf(i - dayOfWeek + 1); // 得到的日期
209 | lunarDay = lc.getLunarDate(year, month, i - dayOfWeek + 1, false);
210 | dayNumber[i] = i - dayOfWeek + 1 + "." + lunarDay;
211 | // 对于当前月才去标记当前日期
212 | if (sys_year.equals(String.valueOf(year)) && sys_month.equals(String.valueOf(month)) && sys_day.equals(day)) {
213 | // 标记当前日期
214 | currentFlag = i;
215 | }
216 | setShowYear(String.valueOf(year));
217 | setShowMonth(String.valueOf(month));
218 | setAnimalsYear(lc.animalsYear(year));
219 | setLeapMonth(lc.leapMonth == 0 ? "" : String.valueOf(lc.leapMonth));
220 | setCyclical(lc.cyclical(year));
221 | } else { // 下一个月
222 | lunarDay = lc.getLunarDate(year, month + 1, j, false);
223 | dayNumber[i] = j + "." + lunarDay;
224 | j++;
225 | }
226 | }
227 |
228 | String abc = "";
229 | for (int i = 0; i < dayNumber.length; i++) {
230 | abc = abc + dayNumber[i] + ":";
231 | }
232 | Log.d("DAYNUMBER", abc);
233 |
234 | }
235 |
236 | public void matchScheduleDate(int year, int month, int day) {
237 |
238 | }
239 |
240 | /**
241 | * 点击每一个item时返回item中的日期
242 | *
243 | * @param position
244 | * @return
245 | */
246 | public String getDateByClickItem(int position) {
247 | return dayNumber[position];
248 | }
249 |
250 | /**
251 | * 在点击gridView时,得到这个月中第一天的位置
252 | *
253 | * @return
254 | */
255 | public int getStartPositon() {
256 | return dayOfWeek + 7;
257 | }
258 |
259 | /**
260 | * 在点击gridView时,得到这个月中最后一天的位置
261 | *
262 | * @return
263 | */
264 | public int getEndPosition() {
265 | return (dayOfWeek + daysOfMonth + 7) - 1;
266 | }
267 |
268 | public String getShowYear() {
269 | return showYear;
270 | }
271 |
272 | public void setShowYear(String showYear) {
273 | this.showYear = showYear;
274 | }
275 |
276 | public String getShowMonth() {
277 | return showMonth;
278 | }
279 |
280 | public void setShowMonth(String showMonth) {
281 | this.showMonth = showMonth;
282 | }
283 |
284 | public String getAnimalsYear() {
285 | return animalsYear;
286 | }
287 |
288 | public void setAnimalsYear(String animalsYear) {
289 | this.animalsYear = animalsYear;
290 | }
291 |
292 | public String getLeapMonth() {
293 | return leapMonth;
294 | }
295 |
296 | public void setLeapMonth(String leapMonth) {
297 | this.leapMonth = leapMonth;
298 | }
299 |
300 | public String getCyclical() {
301 | return cyclical;
302 | }
303 |
304 | public void setCyclical(String cyclical) {
305 | this.cyclical = cyclical;
306 | }
307 | }
308 |
--------------------------------------------------------------------------------
/src/com/example/calendar/LunarCalendar.java:
--------------------------------------------------------------------------------
1 | package com.example.calendar;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Date;
6 |
7 | /**
8 | * 农历算法
9 | *
10 | * @author Vincent Lee
11 | *
12 | */
13 | public class LunarCalendar {
14 | private int year; // 农历的年份
15 | private int month;
16 | private int day;
17 | private String lunarMonth; // 农历的月份
18 | private boolean leap;
19 | public int leapMonth = 0; // 闰的是哪个月
20 |
21 | final static String chineseNumber[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" };
22 | static SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
23 | final static long[] lunarInfo = new long[] { //
24 | 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, //
25 | 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, //
26 | 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, //
27 | 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, //
28 | 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, //
29 | 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0, //
30 | 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, //
31 | 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, //
32 | 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x195a6, 0x095b0, //
33 | 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, //
34 | 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, //
35 | 0x092e0, 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, //
36 | 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, //
37 | 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, //
38 | 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, //
39 | 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, //
40 | 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };
41 |
42 | // 农历部分假日
43 | final static String[] lunarHoliday = new String[] { "0101 春节", "0115 元宵", "0505 端午", "0707 情人", "0715 中元", "0815 中秋", "0909 重阳", "1208 腊八", "1224 小年", "0100 除夕" };
44 |
45 | // 公历部分节假日
46 | final static String[] solarHoliday = new String[] { //
47 | "0101 元旦", "0214 情人", "0308 妇女", "0312 植树", "0315 消费者权益日", "0401 愚人", "0501 劳动", "0504 青年", //
48 | "0512 护士", "0601 儿童", "0701 建党", "0801 建军", "0808 父亲", "0909 毛泽东逝世纪念", "0910 教师", "0928 孔子诞辰",//
49 | "1001 国庆", "1006 老人", "1024 联合国日", "1112 孙中山诞辰纪念", "1220 澳门回归纪念", "1225 圣诞", "1226 毛泽东诞辰纪念" };
50 |
51 | // ====== 传回农历 y年的总天数
52 | final private static int yearDays(int y) {
53 | int i, sum = 348;
54 | for (i = 0x8000; i > 0x8; i >>= 1) {
55 | if ((lunarInfo[y - 1900] & i) != 0)
56 | sum += 1;
57 | }
58 | return (sum + leapDays(y));
59 | }
60 |
61 | // ====== 传回农历 y年闰月的天数
62 | final private static int leapDays(int y) {
63 | if (leapMonth(y) != 0) {
64 | if ((lunarInfo[y - 1900] & 0x10000) != 0)
65 | return 30;
66 | else
67 | return 29;
68 | } else
69 | return 0;
70 | }
71 |
72 | // ====== 传回农历 y年闰哪个月 1-12 , 没闰传回 0
73 | final private static int leapMonth(int y) {
74 | int result = (int) (lunarInfo[y - 1900] & 0xf);
75 | return result;
76 | }
77 |
78 | // ====== 传回农历 y年m月的总天数
79 | final private static int monthDays(int y, int m) {
80 | if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)
81 | return 29;
82 | else
83 | return 30;
84 | }
85 |
86 | // ====== 传回农历 y年的生肖
87 | final public String animalsYear(int year) {
88 | final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };
89 | return Animals[(year - 4) % 12];
90 | }
91 |
92 | // ====== 传入 月日的offset 传回干支, 0=甲子
93 | final private static String cyclicalm(int num) {
94 | final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
95 | final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };
96 | return (Gan[num % 10] + Zhi[num % 12]);
97 | }
98 |
99 | // ====== 传入 offset 传回干支, 0=甲子
100 | final public String cyclical(int year) {
101 | int num = year - 1900 + 36;
102 | return (cyclicalm(num));
103 | }
104 |
105 | public static String getChinaDayString(int day) {
106 | String chineseTen[] = { "初", "十", "廿", "卅" };
107 | int n = day % 10 == 0 ? 9 : day % 10 - 1;
108 | if (day > 30)
109 | return "";
110 | if (day == 10)
111 | return "初十";
112 | else
113 | return chineseTen[day / 10] + chineseNumber[n];
114 | }
115 |
116 | /** */
117 | /**
118 | * 传出y年m月d日对应的农历. yearCyl3:农历年与1864的相差数 ? monCyl4:从1900年1月31日以来,闰月数
119 | * dayCyl5:与1900年1月31日相差的天数,再加40 ?
120 | *
121 | * isday: 这个参数为false---日期为节假日时,阴历日期就返回节假日 ,true---不管日期是否为节假日依然返回这天对应的阴历日期
122 | *
123 | * @param cal
124 | * @return
125 | */
126 | public String getLunarDate(int year_log, int month_log, int day_log, boolean isday) {
127 | // @SuppressWarnings("unused")
128 | int yearCyl, monCyl, dayCyl;
129 | // int leapMonth = 0;
130 | String nowadays;
131 | Date baseDate = null;
132 | Date nowaday = null;
133 | try {
134 | baseDate = chineseDateFormat.parse("1900年1月31日");
135 | } catch (ParseException e) {
136 | e.printStackTrace(); // To change body of catch statement use
137 | // Options | File Templates.
138 | }
139 |
140 | nowadays = year_log + "年" + month_log + "月" + day_log + "日";
141 | try {
142 | nowaday = chineseDateFormat.parse(nowadays);
143 | } catch (ParseException e) {
144 | e.printStackTrace(); // To change body of catch statement use
145 | // Options | File Templates.
146 | }
147 |
148 | // 求出和1900年1月31日相差的天数
149 | int offset = (int) ((nowaday.getTime() - baseDate.getTime()) / 86400000L);
150 | dayCyl = offset + 40;
151 | monCyl = 14;
152 |
153 | // 用offset减去每农历年的天数
154 | // 计算当天是农历第几天
155 | // i最终结果是农历的年份
156 | // offset是当年的第几天
157 | int iYear, daysOfYear = 0;
158 | for (iYear = 1900; iYear < 10000 && offset > 0; iYear++) {
159 | daysOfYear = yearDays(iYear);
160 | offset -= daysOfYear;
161 | monCyl += 12;
162 | }
163 | if (offset < 0) {
164 | offset += daysOfYear;
165 | iYear--;
166 | monCyl -= 12;
167 | }
168 | // 农历年份
169 | year = iYear;
170 | setYear(year); // 设置公历对应的农历年份
171 |
172 | yearCyl = iYear - 1864;
173 | leapMonth = leapMonth(iYear); // 闰哪个月,1-12
174 | leap = false;
175 |
176 | // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
177 | int iMonth, daysOfMonth = 0;
178 | for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
179 | // 闰月
180 | if (leapMonth > 0 && iMonth == (leapMonth + 1) && !leap) {
181 | --iMonth;
182 | leap = true;
183 | daysOfMonth = leapDays(year);
184 | } else
185 | daysOfMonth = monthDays(year, iMonth);
186 |
187 | offset -= daysOfMonth;
188 | // 解除闰月
189 | if (leap && iMonth == (leapMonth + 1))
190 | leap = false;
191 | if (!leap)
192 | monCyl++;
193 | }
194 | // offset为0时,并且刚才计算的月份是闰月,要校正
195 | if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
196 | if (leap) {
197 | leap = false;
198 | } else {
199 | leap = true;
200 | --iMonth;
201 | --monCyl;
202 | }
203 | }
204 | // offset小于0时,也要校正
205 | if (offset < 0) {
206 | offset += daysOfMonth;
207 | --iMonth;
208 | --monCyl;
209 | }
210 | month = iMonth;
211 | setLunarMonth(chineseNumber[month - 1] + "月"); // 设置对应的阴历月份
212 | day = offset + 1;
213 |
214 | if (!isday) {
215 | // 如果日期为节假日则阴历日期则返回节假日
216 | // setLeapMonth(leapMonth);
217 | for (int i = 0; i < solarHoliday.length; i++) {
218 | // 返回公历节假日名称
219 | String sd = solarHoliday[i].split(" ")[0]; // 节假日的日期
220 | String sdv = solarHoliday[i].split(" ")[1]; // 节假日的名称
221 | String smonth_v = month_log + "";
222 | String sday_v = day_log + "";
223 | String smd = "";
224 | if (month_log < 10) {
225 | smonth_v = "0" + month_log;
226 | }
227 | if (day_log < 10) {
228 | sday_v = "0" + day_log;
229 | }
230 | smd = smonth_v + sday_v;
231 | if (sd.trim().equals(smd.trim())) {
232 | return sdv;
233 | }
234 | }
235 |
236 | for (int i = 0; i < lunarHoliday.length; i++) {
237 | // 返回农历节假日名称
238 | String ld = lunarHoliday[i].split(" ")[0]; // 节假日的日期
239 | String ldv = lunarHoliday[i].split(" ")[1]; // 节假日的名称
240 | String lmonth_v = month + "";
241 | String lday_v = day + "";
242 | String lmd = "";
243 | if (month < 10) {
244 | lmonth_v = "0" + month;
245 | }
246 | if (day < 10) {
247 | lday_v = "0" + day;
248 | }
249 | lmd = lmonth_v + lday_v;
250 | if (ld.trim().equals(lmd.trim())) {
251 | return ldv;
252 | }
253 | }
254 | }
255 | if (day == 1)
256 | return chineseNumber[month - 1] + "月";
257 | else
258 | return getChinaDayString(day);
259 |
260 | }
261 |
262 | public String toString() {
263 | if (chineseNumber[month - 1] == "一" && getChinaDayString(day) == "初一")
264 | return "农历" + year + "年";
265 | else if (getChinaDayString(day) == "初一")
266 | return chineseNumber[month - 1] + "月";
267 | else
268 | return getChinaDayString(day);
269 | // return year + "年" + (leap ? "闰" : "") + chineseNumber[month - 1] +
270 | // "月" + getChinaDayString(day);
271 | }
272 |
273 | /*
274 | * public static void main(String[] args) { System.out.println(new
275 | * LunarCalendar().getLunarDate(2012, 1, 23)); }
276 | */
277 |
278 | public int getLeapMonth() {
279 | return leapMonth;
280 | }
281 |
282 | public void setLeapMonth(int leapMonth) {
283 | this.leapMonth = leapMonth;
284 | }
285 |
286 | /**
287 | * 得到当前日期对应的阴历月份
288 | *
289 | * @return
290 | */
291 | public String getLunarMonth() {
292 | return lunarMonth;
293 | }
294 |
295 | public void setLunarMonth(String lunarMonth) {
296 | this.lunarMonth = lunarMonth;
297 | }
298 |
299 | /**
300 | * 得到当前年对应的农历年份
301 | *
302 | * @return
303 | */
304 | public int getYear() {
305 | return year;
306 | }
307 |
308 | public void setYear(int year) {
309 | this.year = year;
310 | }
311 | }
312 |
--------------------------------------------------------------------------------
/src/com/example/calendar/SpecialCalendar.java:
--------------------------------------------------------------------------------
1 | package com.example.calendar;
2 |
3 | import java.util.Calendar;
4 |
5 | /**
6 | * 闰年月算法
7 | *
8 | * @author Vincent Lee
9 | *
10 | */
11 | public class SpecialCalendar {
12 |
13 | private int daysOfMonth = 0; // 某月的天数
14 | private int dayOfWeek = 0; // 具体某一天是星期几
15 |
16 | // 判断是否为闰年
17 | public boolean isLeapYear(int year) {
18 | if (year % 100 == 0 && year % 400 == 0) {
19 | return true;
20 | } else if (year % 100 != 0 && year % 4 == 0) {
21 | return true;
22 | }
23 | return false;
24 | }
25 |
26 | // 得到某月有多少天数
27 | public int getDaysOfMonth(boolean isLeapyear, int month) {
28 | switch (month) {
29 | case 1:
30 | case 3:
31 | case 5:
32 | case 7:
33 | case 8:
34 | case 10:
35 | case 12:
36 | daysOfMonth = 31;
37 | break;
38 | case 4:
39 | case 6:
40 | case 9:
41 | case 11:
42 | daysOfMonth = 30;
43 | break;
44 | case 2:
45 | if (isLeapyear) {
46 | daysOfMonth = 29;
47 | } else {
48 | daysOfMonth = 28;
49 | }
50 |
51 | }
52 | return daysOfMonth;
53 | }
54 |
55 | // 指定某年中的某月的第一天是星期几
56 | public int getWeekdayOfMonth(int year, int month) {
57 | Calendar cal = Calendar.getInstance();
58 | cal.set(year, month - 1, 1);
59 | dayOfWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;
60 | return dayOfWeek;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------