listWorkOrRelax
32 |
33 | 我们通过这两个集合进行存储,然后绘制。
34 |
35 | 具体实现大家拷贝源码吧!
36 |
37 | [博客](http://blog.csdn.net/mr_dsw/article/details/48755993)
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/bin/CalendarView.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/CalendarView.apk
--------------------------------------------------------------------------------
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/classes.dex
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-98626dc61b6503be8127c5cd0090d83f.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/dexedLibs/android-support-v4-98626dc61b6503be8127c5cd0090d83f.jar
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/left_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/res/crunch/drawable-hdpi/left_arrow.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/right_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/res/crunch/drawable-hdpi/right_arrow.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/bin/resources.ap_
--------------------------------------------------------------------------------
/gen/com/dsw/calendarview/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.dsw.calendarview;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/gen/com/dsw/calendarview/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.dsw.calendarview;
9 |
10 | public final class R {
11 | public static final class array {
12 | public static final int week_name=0x7f070000;
13 | }
14 | public static final class attr {
15 | /** May be a reference to another resource, in the form "@[+][package:]type:name
"
16 | or to a theme attribute in the form "?[package:][type:]name
".
17 |
May be a color value, in the form of "#rgb
", "#argb
",
18 | "#rrggbb
", or "#aarrggbb
".
19 | */
20 | public static final int CircleColor=0x7f010004;
21 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
22 | or to a theme attribute in the form "?[package:][type:]name
".
23 |
May be a color value, in the form of "#rgb
", "#argb
",
24 | "#rrggbb
", or "#aarrggbb
".
25 | */
26 | public static final int CurrentColor=0x7f010002;
27 | /**
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
28 | Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
29 | in (inches), mm (millimeters).
30 |
This may also be a reference to a resource (in the form
31 | "@[package:]type:name
") or
32 | theme attribute (in the form
33 | "?[package:][type:]name
")
34 | containing a value of this type.
35 | */
36 | public static final int DateHeight=0x7f01000a;
37 | /**
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
38 | Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
39 | in (inches), mm (millimeters).
40 |
This may also be a reference to a resource (in the form
41 | "@[package:]type:name
") or
42 | theme attribute (in the form
43 | "?[package:][type:]name
")
44 | containing a value of this type.
45 | */
46 | public static final int DateSize=0x7f010008;
47 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
48 | or to a theme attribute in the form "?[package:][type:]name
".
49 |
May be a color value, in the form of "#rgb
", "#argb
",
50 | "#rrggbb
", or "#aarrggbb
".
51 | */
52 | public static final int EnableDateColor=0x7f010000;
53 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
54 | or to a theme attribute in the form "?[package:][type:]name
".
55 |
May be a color value, in the form of "#rgb
", "#argb
",
56 | "#rrggbb
", or "#aarrggbb
".
57 | */
58 | public static final int PriceColor=0x7f010007;
59 | /**
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
60 | Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
61 | in (inches), mm (millimeters).
62 |
This may also be a reference to a resource (in the form
63 | "@[package:]type:name
") or
64 | theme attribute (in the form
65 | "?[package:][type:]name
")
66 | containing a value of this type.
67 | */
68 | public static final int PriceSize=0x7f010009;
69 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
70 | or to a theme attribute in the form "?[package:][type:]name
".
71 |
May be a color value, in the form of "#rgb
", "#argb
",
72 | "#rrggbb
", or "#aarrggbb
".
73 | */
74 | public static final int RelaxColor=0x7f010005;
75 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
76 | or to a theme attribute in the form "?[package:][type:]name
".
77 |
May be a color value, in the form of "#rgb
", "#argb
",
78 | "#rrggbb
", or "#aarrggbb
".
79 | */
80 | public static final int SelectBGColor=0x7f010003;
81 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
82 | or to a theme attribute in the form "?[package:][type:]name
".
83 |
May be a color value, in the form of "#rgb
", "#argb
",
84 | "#rrggbb
", or "#aarrggbb
".
85 | */
86 | public static final int UnableDateColor=0x7f010001;
87 | /**
May be a reference to another resource, in the form "@[+][package:]type:name
"
88 | or to a theme attribute in the form "?[package:][type:]name
".
89 |
May be a color value, in the form of "#rgb
", "#argb
",
90 | "#rrggbb
", or "#aarrggbb
".
91 | */
92 | public static final int WorkColor=0x7f010006;
93 | }
94 | public static final class color {
95 | public static final int blue_black=0x7f040013;
96 | /** 偶数行颜色
97 | */
98 | public static final int border_color=0x7f040001;
99 | public static final int current_day_color=0x7f04000b;
100 | public static final int date_background=0x7f040005;
101 | public static final int day_color=0x7f040006;
102 | /** 奇数行颜色
103 | */
104 | public static final int even=0x7f040000;
105 | public static final int green_black=0x7f040014;
106 | public static final int inner_grid_color=0x7f040007;
107 | public static final int prev_next_month_day_color=0x7f040008;
108 | public static final int recordremindtext_color=0x7f04000a;
109 | public static final int red=0x7f040012;
110 | public static final int selectdeparment=0x7f04000f;
111 | public static final int split_line_grey=0x7f040010;
112 | public static final int sunday_saturday_color=0x7f040004;
113 | public static final int sunday_saturday_prev_next_month_day_color=0x7f04000e;
114 | public static final int text_color=0x7f040009;
115 | public static final int today_background_color=0x7f04000c;
116 | public static final int today_color=0x7f04000d;
117 | public static final int translate=0x7f040011;
118 | public static final int week_name=0x7f040003;
119 | public static final int week_today=0x7f040002;
120 | }
121 | public static final class dimen {
122 | public static final int action_size=0x7f050006;
123 | /** Default screen margins, per the Android Design guidelines.
124 |
125 | Example customization of dimensions originally defined in res/values/dimens.xml
126 | (such as screen margins) for screens with more than 820dp of available width. This
127 | would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively).
128 |
129 | */
130 | public static final int activity_horizontal_margin=0x7f050000;
131 | public static final int activity_vertical_margin=0x7f050001;
132 | /** 日历边框
133 | */
134 | public static final int calendar_border_margin=0x7f050002;
135 | public static final int day_size=0x7f050005;
136 | public static final int day_top_offset=0x7f050007;
137 | public static final int weekname_margin=0x7f050004;
138 | /** 日历周名
139 | */
140 | public static final int weekname_size=0x7f050003;
141 | }
142 | public static final class drawable {
143 | public static final int back_border=0x7f020000;
144 | public static final int ic_launcher=0x7f020001;
145 | public static final int left_arrow=0x7f020002;
146 | public static final int right_arrow=0x7f020003;
147 | }
148 | public static final class id {
149 | public static final int action_settings=0x7f0a0009;
150 | public static final int calendarView=0x7f0a0008;
151 | public static final int date_operator_ll=0x7f0a0002;
152 | public static final int date_text=0x7f0a0004;
153 | public static final int iv_left=0x7f0a0000;
154 | public static final int iv_right=0x7f0a0001;
155 | public static final int monthDateView=0x7f0a0005;
156 | public static final int selectDate_description=0x7f0a0007;
157 | public static final int selectDate_text=0x7f0a0006;
158 | public static final int tv_today=0x7f0a0003;
159 | }
160 | public static final class layout {
161 | public static final int activity_date=0x7f030000;
162 | public static final int activity_main=0x7f030001;
163 | }
164 | public static final class menu {
165 | public static final int main=0x7f090000;
166 | }
167 | public static final class string {
168 | public static final int action_settings=0x7f060002;
169 | public static final int app_name=0x7f060000;
170 | public static final int hello_world=0x7f060001;
171 | }
172 | public static final class style {
173 | /**
174 | Base application theme, dependent on API level. This theme is replaced
175 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
176 |
177 |
178 | Theme customizations available in newer API levels can go in
179 | res/values-vXX/styles.xml, while customizations related to
180 | backward-compatibility can go here.
181 |
182 |
183 | Base application theme for API 11+. This theme completely replaces
184 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
185 |
186 | API 11 theme customizations can go here.
187 |
188 | Base application theme for API 14+. This theme completely replaces
189 | AppBaseTheme from BOTH res/values/styles.xml and
190 | res/values-v11/styles.xml on API 14+ devices.
191 |
192 | API 14 theme customizations can go here.
193 | */
194 | public static final int AppBaseTheme=0x7f080000;
195 | /** Application theme.
196 | All customizations that are NOT specific to a particular API-level can go here.
197 | */
198 | public static final int AppTheme=0x7f080001;
199 | public static final int myschedule_current_month_tv=0x7f080002;
200 | }
201 | public static final class styleable {
202 | /** Attributes that can be used with a CalendarView.
203 |
Includes the following attributes:
204 |
205 |
206 |
207 | Attribute | Description |
208 | {@link #CalendarView_CircleColor com.dsw.calendarview:CircleColor} | |
209 | {@link #CalendarView_CurrentColor com.dsw.calendarview:CurrentColor} | |
210 | {@link #CalendarView_DateHeight com.dsw.calendarview:DateHeight} | |
211 | {@link #CalendarView_DateSize com.dsw.calendarview:DateSize} | |
212 | {@link #CalendarView_EnableDateColor com.dsw.calendarview:EnableDateColor} | |
213 | {@link #CalendarView_PriceColor com.dsw.calendarview:PriceColor} | |
214 | {@link #CalendarView_PriceSize com.dsw.calendarview:PriceSize} | |
215 | {@link #CalendarView_RelaxColor com.dsw.calendarview:RelaxColor} | |
216 | {@link #CalendarView_SelectBGColor com.dsw.calendarview:SelectBGColor} | |
217 | {@link #CalendarView_UnableDateColor com.dsw.calendarview:UnableDateColor} | |
218 | {@link #CalendarView_WorkColor com.dsw.calendarview:WorkColor} | |
219 |
220 | @see #CalendarView_CircleColor
221 | @see #CalendarView_CurrentColor
222 | @see #CalendarView_DateHeight
223 | @see #CalendarView_DateSize
224 | @see #CalendarView_EnableDateColor
225 | @see #CalendarView_PriceColor
226 | @see #CalendarView_PriceSize
227 | @see #CalendarView_RelaxColor
228 | @see #CalendarView_SelectBGColor
229 | @see #CalendarView_UnableDateColor
230 | @see #CalendarView_WorkColor
231 | */
232 | public static final int[] CalendarView = {
233 | 0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003,
234 | 0x7f010004, 0x7f010005, 0x7f010006, 0x7f010007,
235 | 0x7f010008, 0x7f010009, 0x7f01000a
236 | };
237 | /**
238 | This symbol is the offset where the {@link com.dsw.calendarview.R.attr#CircleColor}
239 | attribute's value can be found in the {@link #CalendarView} array.
240 |
241 |
242 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
243 | or to a theme attribute in the form "?[package:][type:]name
".
244 |
May be a color value, in the form of "#rgb
", "#argb
",
245 | "#rrggbb
", or "#aarrggbb
".
246 | @attr name com.dsw.calendarview:CircleColor
247 | */
248 | public static final int CalendarView_CircleColor = 4;
249 | /**
250 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#CurrentColor}
251 | attribute's value can be found in the {@link #CalendarView} array.
252 |
253 |
254 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
255 | or to a theme attribute in the form "?[package:][type:]name
".
256 |
May be a color value, in the form of "#rgb
", "#argb
",
257 | "#rrggbb
", or "#aarrggbb
".
258 | @attr name com.dsw.calendarview:CurrentColor
259 | */
260 | public static final int CalendarView_CurrentColor = 2;
261 | /**
262 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#DateHeight}
263 | attribute's value can be found in the {@link #CalendarView} array.
264 |
265 |
266 |
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
267 | Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
268 | in (inches), mm (millimeters).
269 |
This may also be a reference to a resource (in the form
270 | "@[package:]type:name
") or
271 | theme attribute (in the form
272 | "?[package:][type:]name
")
273 | containing a value of this type.
274 | @attr name com.dsw.calendarview:DateHeight
275 | */
276 | public static final int CalendarView_DateHeight = 10;
277 | /**
278 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#DateSize}
279 | attribute's value can be found in the {@link #CalendarView} array.
280 |
281 |
282 |
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
283 | Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
284 | in (inches), mm (millimeters).
285 |
This may also be a reference to a resource (in the form
286 | "@[package:]type:name
") or
287 | theme attribute (in the form
288 | "?[package:][type:]name
")
289 | containing a value of this type.
290 | @attr name com.dsw.calendarview:DateSize
291 | */
292 | public static final int CalendarView_DateSize = 8;
293 | /**
294 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#EnableDateColor}
295 | attribute's value can be found in the {@link #CalendarView} array.
296 |
297 |
298 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
299 | or to a theme attribute in the form "?[package:][type:]name
".
300 |
May be a color value, in the form of "#rgb
", "#argb
",
301 | "#rrggbb
", or "#aarrggbb
".
302 | @attr name com.dsw.calendarview:EnableDateColor
303 | */
304 | public static final int CalendarView_EnableDateColor = 0;
305 | /**
306 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#PriceColor}
307 | attribute's value can be found in the {@link #CalendarView} array.
308 |
309 |
310 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
311 | or to a theme attribute in the form "?[package:][type:]name
".
312 |
May be a color value, in the form of "#rgb
", "#argb
",
313 | "#rrggbb
", or "#aarrggbb
".
314 | @attr name com.dsw.calendarview:PriceColor
315 | */
316 | public static final int CalendarView_PriceColor = 7;
317 | /**
318 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#PriceSize}
319 | attribute's value can be found in the {@link #CalendarView} array.
320 |
321 |
322 |
Must be a dimension value, which is a floating point number appended with a unit such as "14.5sp
".
323 | Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),
324 | in (inches), mm (millimeters).
325 |
This may also be a reference to a resource (in the form
326 | "@[package:]type:name
") or
327 | theme attribute (in the form
328 | "?[package:][type:]name
")
329 | containing a value of this type.
330 | @attr name com.dsw.calendarview:PriceSize
331 | */
332 | public static final int CalendarView_PriceSize = 9;
333 | /**
334 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#RelaxColor}
335 | attribute's value can be found in the {@link #CalendarView} array.
336 |
337 |
338 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
339 | or to a theme attribute in the form "?[package:][type:]name
".
340 |
May be a color value, in the form of "#rgb
", "#argb
",
341 | "#rrggbb
", or "#aarrggbb
".
342 | @attr name com.dsw.calendarview:RelaxColor
343 | */
344 | public static final int CalendarView_RelaxColor = 5;
345 | /**
346 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#SelectBGColor}
347 | attribute's value can be found in the {@link #CalendarView} array.
348 |
349 |
350 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
351 | or to a theme attribute in the form "?[package:][type:]name
".
352 |
May be a color value, in the form of "#rgb
", "#argb
",
353 | "#rrggbb
", or "#aarrggbb
".
354 | @attr name com.dsw.calendarview:SelectBGColor
355 | */
356 | public static final int CalendarView_SelectBGColor = 3;
357 | /**
358 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#UnableDateColor}
359 | attribute's value can be found in the {@link #CalendarView} array.
360 |
361 |
362 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
363 | or to a theme attribute in the form "?[package:][type:]name
".
364 |
May be a color value, in the form of "#rgb
", "#argb
",
365 | "#rrggbb
", or "#aarrggbb
".
366 | @attr name com.dsw.calendarview:UnableDateColor
367 | */
368 | public static final int CalendarView_UnableDateColor = 1;
369 | /**
370 |
This symbol is the offset where the {@link com.dsw.calendarview.R.attr#WorkColor}
371 | attribute's value can be found in the {@link #CalendarView} array.
372 |
373 |
374 |
May be a reference to another resource, in the form "@[+][package:]type:name
"
375 | or to a theme attribute in the form "?[package:][type:]name
".
376 |
May be a color value, in the form of "#rgb
", "#argb
",
377 | "#rrggbb
", or "#aarrggbb
".
378 | @attr name com.dsw.calendarview:WorkColor
379 | */
380 | public static final int CalendarView_WorkColor = 6;
381 | };
382 | }
383 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/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-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/left_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/res/drawable-hdpi/left_arrow.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/right_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/res/drawable-hdpi/right_arrow.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dengshiwei/CalendarView/654d4c115ca6be8f25f75402dc72ff368c6c33c3/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/back_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/res/layout/activity_date.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
23 |
31 |
39 |
49 |
50 |
59 |
60 |
61 |
66 |
67 |
70 |
85 |
89 |
100 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/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-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 | 64dp
9 |
10 |
11 |
--------------------------------------------------------------------------------
/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #FFADD8E6
5 |
6 | #000000
7 | #0078ff
8 | #1FC2F3
9 | #fa4451
10 | #ffffff
11 | #000000
12 | #aaadb2
13 | #AAAAAA
14 | #FFFF00
15 | #000000
16 | #565656
17 | #FF0000
18 | #565656
19 | #AAAAAA
20 | #599cd5
21 | #EBEBEB
22 | #00000000
23 | #FFFF0000
24 | #3bac
25 | #549008
26 |
27 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 | 0dp
8 |
9 |
10 | 14dp
11 | 8dp
12 | 18dp
13 | 12dp
14 | 16dp
15 |
16 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | CalendarView
5 | Hello world!
6 | Settings
7 |
8 | - 日
9 | - 一
10 | - 二
11 | - 三
12 | - 四
13 | - 五
14 | - 六
15 |
16 |
17 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
23 |
24 |
--------------------------------------------------------------------------------
/src/com/dsw/calendarview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dsw.calendarview;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.os.Bundle;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.widget.Toast;
9 |
10 | import com.dsw.datepicker.CalendarView;
11 | import com.dsw.datepicker.CalendarView.DateViewClick;
12 | import com.dsw.datepicker.DayAndPrice;
13 | import com.dsw.datepicker.WorkOrRelax;
14 |
15 | public class MainActivity extends FragmentActivity {
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | List list = new ArrayList();
20 | DayAndPrice dAndPrice = new DayAndPrice("¥3900起", 2016,2,20);
21 | DayAndPrice dAndPrice1 = new DayAndPrice("¥3900起", 2016,2,10);
22 | DayAndPrice dAndPrice2 = new DayAndPrice("¥3900起", 2016,2,18);
23 | DayAndPrice dAndPrice3 = new DayAndPrice("¥3900起", 2016,2,25);
24 | DayAndPrice dAndPrice4 = new DayAndPrice("¥3900起", 2016,3,5);
25 | DayAndPrice dAndPrice5 = new DayAndPrice("¥3900起", 2016,3,11);
26 | DayAndPrice dAndPrice6 = new DayAndPrice("¥3900起", 2016,3,15);
27 | DayAndPrice dAndPrice7 = new DayAndPrice("¥3900起", 2016,4,25);
28 | DayAndPrice dAndPrice8 = new DayAndPrice("¥3900起", 2016,4,1);
29 | DayAndPrice dAndPrice9 = new DayAndPrice("¥3900起", 2016,4,13);
30 | DayAndPrice dAndPrice10 = new DayAndPrice("¥3900起", 2016,5,16);
31 | DayAndPrice dAndPrice11 = new DayAndPrice("¥3900起", 2016,5,2);
32 | DayAndPrice dAndPrice12 = new DayAndPrice("¥3900起", 2016,5,4);
33 | DayAndPrice dAndPrice13 = new DayAndPrice("¥3900起", 2016,5,25);
34 | list.add(dAndPrice);list.add(dAndPrice1);list.add(dAndPrice2);list.add(dAndPrice3);
35 | list.add(dAndPrice4);list.add(dAndPrice5);list.add(dAndPrice6);list.add(dAndPrice7);
36 | list.add(dAndPrice8);list.add(dAndPrice9);list.add(dAndPrice10);list.add(dAndPrice11);
37 | list.add(dAndPrice12);list.add(dAndPrice13);
38 | List listDate = new ArrayList();
39 | WorkOrRelax workOrRelax = new WorkOrRelax(2016,2,6,0);
40 | WorkOrRelax workOrRelax1 = new WorkOrRelax(2016,2,7,1);
41 | WorkOrRelax workOrRelax2 = new WorkOrRelax(2016,2,8,1);
42 | WorkOrRelax workOrRelax3 = new WorkOrRelax(2016,2,9,1);
43 | WorkOrRelax workOrRelax4 = new WorkOrRelax(2016,2,10,1);
44 | WorkOrRelax workOrRelax5 = new WorkOrRelax(2016,2,11,1);
45 | WorkOrRelax workOrRelax6 = new WorkOrRelax(2016,2,12,1);
46 | WorkOrRelax workOrRelax7 = new WorkOrRelax(2016,2,13,1);
47 | WorkOrRelax workOrRelax8 = new WorkOrRelax(2016,2,14,1);
48 | listDate.add(workOrRelax);listDate.add(workOrRelax1);listDate.add(workOrRelax2);listDate.add(workOrRelax3);
49 | listDate.add(workOrRelax4);listDate.add(workOrRelax5);listDate.add(workOrRelax6);listDate.add(workOrRelax7);
50 | listDate.add(workOrRelax8);
51 | setContentView(R.layout.activity_main);
52 | final CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
53 | calendarView.setListDayAndPrice(list);
54 | calendarView.setListWorkOrRelax(listDate);
55 | calendarView.setDateViewClick(new DateViewClick() {
56 |
57 | @Override
58 | public void dateClick() {
59 | Toast.makeText(getApplication(), "点击了:" + calendarView.getSelectMonth(), Toast.LENGTH_SHORT).show();
60 | }
61 | });
62 | }
63 |
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/CalendarUtil.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import java.text.ParseException;
4 | import java.text.SimpleDateFormat;
5 | import java.util.Calendar;
6 | import java.util.Date;
7 |
8 | import android.text.TextUtils;
9 |
10 | /**
11 | * 把公历时间处理成农历时间
12 | */
13 | public class CalendarUtil {
14 | /**
15 | * 用于保存中文的月份
16 | */
17 | private final static String CHINESE_NUMBER[] = { "一", "二", "三", "四", "五",
18 | "六", "七", "八", "九", "十", "十一", "腊" };
19 |
20 | /**
21 | * 用于保存展示周几使用
22 | */
23 | private final static String WEEK_NUMBER[] = { "日", "一", "二", "三", "四", "五",
24 | "六" };
25 |
26 | private final static long[] LUNAR_INFO = new long[] { 0x04bd8, 0x04ae0,
27 | 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0,
28 | 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540,
29 | 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5,
30 | 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970,
31 | 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3,
32 | 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0,
33 | 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0,
34 | 0x0b550, 0x15355, 0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8,
35 | 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570,
36 | 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5,
37 | 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0,
38 | 0x195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50,
39 | 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0,
40 | 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0,
41 | 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7,
42 | 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50,
43 | 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954,
44 | 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260,
45 | 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0,
46 | 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0,
47 | 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20,
48 | 0x0ada0 };
49 |
50 | /**
51 | * 转换为2012年11月22日格式
52 | */
53 | private static SimpleDateFormat chineseDateFormat = new SimpleDateFormat(
54 | "yyyy年MM月dd日");
55 | /**
56 | * 转换为2012-11-22格式
57 | */
58 | private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
59 | "yyyy-MM-dd");
60 |
61 | /**
62 | * 计算得到农历的年份
63 | */
64 | private int mLuchYear;
65 | /**
66 | * 计算得到农历的月份
67 | */
68 | private int mLuchMonth;
69 |
70 | /**
71 | * 计算得到农历的日期
72 | */
73 | private int mLuchDay;
74 |
75 | /**
76 | * 用于标识是事为闰年
77 | */
78 | private boolean isLoap;
79 |
80 | /**
81 | * 用于记录当前处理的时间
82 | */
83 | private Calendar mCurrenCalendar;
84 |
85 | /**
86 | * 传回农历 year年的总天数
87 | *
88 | * @param year
89 | * 将要计算的年份
90 | * @return 返回传入年份的总天数
91 | */
92 | private static int yearDays(int year) {
93 | int i, sum = 348;
94 | for (i = 0x8000; i > 0x8; i >>= 1) {
95 | if ((LUNAR_INFO[year - 1900] & i) != 0)
96 | sum += 1;
97 | }
98 | return (sum + leapDays(year));
99 | }
100 |
101 | /**
102 | * 传回农历 year年闰月的天数
103 | *
104 | * @param year
105 | * 将要计算的年份
106 | * @return 返回 农历 year年闰月的天数
107 | */
108 | private static int leapDays(int year) {
109 | if (leapMonth(year) != 0) {
110 | if ((LUNAR_INFO[year - 1900] & 0x10000) != 0)
111 | return 30;
112 | else
113 | return 29;
114 | } else
115 | return 0;
116 | }
117 |
118 | /**
119 | * 传回农历 year年闰哪个月 1-12 , 没闰传回 0
120 | *
121 | * @param year
122 | * 将要计算的年份
123 | * @return 传回农历 year年闰哪个月 1-12 , 没闰传回 0
124 | */
125 | private static int leapMonth(int year) {
126 | return (int) (LUNAR_INFO[year - 1900] & 0xf);
127 | }
128 |
129 | /**
130 | * 传回农历 year年month月的总天数
131 | *
132 | * @param year
133 | * 将要计算的年份
134 | * @param month
135 | * 将要计算的月份
136 | * @return 传回农历 year年month月的总天数
137 | */
138 | private static int monthDays(int year, int month) {
139 | if ((LUNAR_INFO[year - 1900] & (0x10000 >> month)) == 0)
140 | return 29;
141 | else
142 | return 30;
143 | }
144 |
145 | /**
146 | * 传回农历 y年的生肖
147 | *
148 | * @return 传回农历 y年的生肖
149 | */
150 | public String animalsYear() {
151 | final String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇",
152 | "马", "羊", "猴", "鸡", "狗", "猪" };
153 | return Animals[(mLuchYear - 4) % 12];
154 | }
155 |
156 | // ====== 传入 月日的offset 传回干支, 0=甲子
157 | private static String cyclicalm(int num) {
158 | final String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚",
159 | "辛", "壬", "癸" };
160 | final String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午",
161 | "未", "申", "酉", "戌", "亥" };
162 |
163 | return (Gan[num % 10] + Zhi[num % 12]);
164 | }
165 |
166 | // ====== 传入 offset 传回干支, 0=甲子
167 | public String cyclical() {
168 | int num = mLuchYear - 1900 + 36;
169 | return (cyclicalm(num));
170 | }
171 |
172 | /**
173 | * 传出y年m月d日对应的农历. yearCyl3:农历年与1864的相差数 ? monCyl4:从1900年1月31日以来,闰月数
174 | * dayCyl5:与1900年1月31日相差的天数,再加40 ?
175 | *
176 | * @param cal
177 | * @return
178 | */
179 | public CalendarUtil(Calendar cal) {
180 | mCurrenCalendar = cal;
181 | int leapMonth = 0;
182 | Date baseDate = null;
183 | try {
184 | baseDate = chineseDateFormat.parse("1900年1月31日");
185 | } catch (ParseException e) {
186 | e.printStackTrace(); // To change body of catch statement use
187 | // Options | File Templates.
188 | }
189 |
190 | // 求出和1900年1月31日相差的天数
191 | int offset = (int) ((cal.getTime().getTime() - baseDate.getTime()) / 86400000L);
192 | // 用offset减去每农历年的天数
193 | // 计算当天是农历第几天
194 | // i最终结果是农历的年份
195 | // offset是当年的第几天
196 | int iYear, daysOfYear = 0;
197 | for (iYear = 1900; iYear < 2050 && offset > 0; iYear++) {
198 | daysOfYear = yearDays(iYear);
199 | offset -= daysOfYear;
200 | }
201 | if (offset < 0) {
202 | offset += daysOfYear;
203 | iYear--;
204 | }
205 | // 农历年份
206 | mLuchYear = iYear;
207 |
208 | leapMonth = leapMonth(iYear); // 闰哪个月,1-12
209 | isLoap = false;
210 |
211 | // 用当年的天数offset,逐个减去每月(农历)的天数,求出当天是本月的第几天
212 | int iMonth, daysOfMonth = 0;
213 | for (iMonth = 1; iMonth < 13 && offset > 0; iMonth++) {
214 | // 闰月
215 | if (leapMonth > 0 && iMonth == (leapMonth + 1) && !isLoap) {
216 | --iMonth;
217 | isLoap = true;
218 | daysOfMonth = leapDays(mLuchYear);
219 | } else
220 | daysOfMonth = monthDays(mLuchYear, iMonth);
221 |
222 | offset -= daysOfMonth;
223 | // 解除闰月
224 | if (isLoap && iMonth == (leapMonth + 1))
225 | isLoap = false;
226 | if (!isLoap) {
227 | }
228 | }
229 | // offset为0时,并且刚才计算的月份是闰月,要校正
230 | if (offset == 0 && leapMonth > 0 && iMonth == leapMonth + 1) {
231 | if (isLoap) {
232 | isLoap = false;
233 | } else {
234 | isLoap = true;
235 | --iMonth;
236 | }
237 | }
238 | // offset小于0时,也要校正
239 | if (offset < 0) {
240 | offset += daysOfMonth;
241 | --iMonth;
242 |
243 | }
244 | mLuchMonth = iMonth;
245 | mLuchDay = offset + 1;
246 | }
247 |
248 | /**
249 | * 返化成中文格式
250 | *
251 | * @param day
252 | * @return
253 | */
254 | public static String getChinaDayString(int day) {
255 | String chineseTen[] = { "初", "十", "廿", "卅" };
256 | int n = day % 10 == 0 ? 9 : day % 10 - 1;
257 | if (day > 30)
258 | return "";
259 | if (day == 10)
260 | return "初十";
261 | else
262 | return chineseTen[day / 10] + CHINESE_NUMBER[n];
263 | }
264 |
265 | /**
266 | * 用于显示农历的初几这种格式
267 | *
268 | * @return 农历的日期
269 | */
270 | public String toString() {
271 | String message = "";
272 | // int n = mLuchDay % 10 == 0 ? 9 : mLuchDay % 10 - 1;
273 | message = getChinaCalendarMsg(mLuchYear, mLuchMonth, mLuchDay);
274 | if (TextUtils.isEmpty(message)) {
275 | String solarMsg = new SolarTermsUtil(mCurrenCalendar).getSolartermsMsg();
276 | // 判断当前日期是否为节气
277 | if (!TextUtils.isEmpty(solarMsg)) {
278 | message = solarMsg;
279 | } else {
280 | /**
281 | * 判断当前日期是否为公历节日
282 | */
283 | String gremessage = new GregorianUtil(mCurrenCalendar).getGremessage();
284 | if (!TextUtils.isEmpty(gremessage)) {
285 | message = gremessage;
286 | } else if (mLuchDay == 1) {
287 | message = CHINESE_NUMBER[mLuchMonth - 1] + "月";
288 | } else {
289 | message = getChinaDayString(mLuchDay);
290 | }
291 |
292 | }
293 | }
294 | return message;
295 | }
296 |
297 | /**
298 | * 获取假日信息
299 | * @return 对应的假日
300 | */
301 | public String getHolidayMsg(){
302 | String message = "";
303 | message = getChinaCalendarMsg(mLuchYear, mLuchMonth, mLuchDay);
304 | if (TextUtils.isEmpty(message)) {
305 | String solarMsg = new SolarTermsUtil(mCurrenCalendar).getSolartermsMsg();
306 | // 判断当前日期是否为节气
307 | if (!TextUtils.isEmpty(solarMsg)) {
308 | message = solarMsg;
309 | } else {
310 | /**
311 | * 判断当前日期是否为公历节日
312 | */
313 | String gremessage = new GregorianUtil(mCurrenCalendar).getGremessage();
314 | if (!TextUtils.isEmpty(gremessage)) {
315 | message = gremessage;
316 | }
317 | }
318 | }
319 | return message;
320 | }
321 |
322 | /**
323 | * 返回农历的年月日
324 | *
325 | * @return 农历的年月日格式
326 | */
327 | public String getDay() {
328 | return (isLoap ? "闰" : "") + CHINESE_NUMBER[mLuchMonth - 1] + "月"
329 | + getChinaDayString(mLuchDay);
330 | }
331 |
332 | /**
333 | * 把calendar转化为当前年月日
334 | *
335 | * @param calendar
336 | * Calendar
337 | * @return 返回成转换好的 年月日格式
338 | */
339 | public static String getDay(Calendar calendar) {
340 | return simpleDateFormat.format(calendar.getTime());
341 | }
342 |
343 | /**
344 | * 用于比对二个日期的大小
345 | *
346 | * @param compareDate
347 | * 将要比对的时间
348 | * @param currentDate
349 | * 当前时间
350 | * @return true 表示大于当前时间 false 表示小于当前时间
351 | */
352 | public static boolean compare(Date compareDate, Date currentDate) {
353 | return chineseDateFormat.format(compareDate).compareTo(
354 | chineseDateFormat.format(currentDate)) >= 0;
355 | }
356 |
357 | /**
358 | * 获取当前周几
359 | *
360 | * @param calendar
361 | * @return
362 | */
363 | public static String getWeek(Calendar calendar) {
364 | return "周" + WEEK_NUMBER[calendar.get(Calendar.DAY_OF_WEEK) - 1] + "";
365 | }
366 |
367 | /**
368 | * 将当前时间转换成要展示的形式
369 | *
370 | * @param calendar
371 | * @return
372 | */
373 | public static String getCurrentDay(Calendar calendar) {
374 | return getDay(calendar) + " 农历" + new CalendarUtil(calendar).getDay()
375 | + " " + getWeek(calendar);
376 | }
377 |
378 | /**
379 | * 用于获取中国的传统节日
380 | *
381 | * @param month
382 | * 农历的月
383 | * @param day
384 | * 农历日
385 | * @return 中国传统节日
386 | */
387 | private String getChinaCalendarMsg(int year, int month, int day) {
388 | String message = "";
389 | if (((month) == 1) && day == 1) {
390 | message = "春节";
391 | } else if (((month) == 1) && day == 15) {
392 | message = "元宵节";
393 | } else if (((month) == 5) && day == 5) {
394 | message = "端午节";
395 | } else if ((month == 7) && day == 7) {
396 | message = "七夕";
397 | } else if (((month) == 8) && day == 15) {
398 | message = "中秋节";
399 | } else if ((month == 9) && day == 9) {
400 | message = "重阳节";
401 | } else if ((month == 12) && day == 8) {
402 | message = "腊八";
403 | } else {
404 | if (month == 12) {
405 | if ((((monthDays(year, month) == 29) && day == 29))
406 | || ((((monthDays(year, month) == 30) && day == 30)))) {
407 | message = "除夕";
408 | }
409 | }
410 | }
411 | return message;
412 | }
413 | }
414 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/CalendarView.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | import android.content.Context;
7 | import android.util.AttributeSet;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 |
14 | import com.dsw.calendarview.R;
15 | import com.dsw.datepicker.MonthDateView.DateClick;
16 |
17 | public class CalendarView extends LinearLayout {
18 | private ImageView iv_left;
19 | private ImageView iv_right;
20 | private TextView tv_date;
21 | private TextView tv_week;
22 | private TextView tv_today;
23 | private MonthDateView monthDateView;
24 | private DateViewClick dateViewClick;
25 | private List listDayAndPrice = new ArrayList();
26 | private List listWorkOrRelax = new ArrayList();
27 | public CalendarView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | View view = LayoutInflater.from(context).inflate(R.layout.activity_date, this);
30 | iv_left = (ImageView) view.findViewById(R.id.iv_left);
31 | iv_right = (ImageView) view.findViewById(R.id.iv_right);
32 | monthDateView = (MonthDateView) view.findViewById(R.id.monthDateView);
33 | tv_date = (TextView) view.findViewById(R.id.date_text);
34 | tv_week =(TextView) view.findViewById(R.id.selectDate_text);
35 | tv_today = (TextView) view.findViewById(R.id.tv_today);
36 | monthDateView.setTextView(tv_date,tv_week);
37 | monthDateView.setDayAndPriceList(listDayAndPrice);
38 | monthDateView.setDaysWorkOrRelaxList(listWorkOrRelax);
39 | monthDateView.setDateClick(new DateClick() {
40 |
41 | @Override
42 | public void onClickOnDate() {
43 | if(dateViewClick != null){
44 | dateViewClick.dateClick();
45 | }
46 | }
47 | });
48 | setOnlistener();
49 | }
50 | /**
51 | * 设置监听
52 | */
53 | private void setOnlistener(){
54 | iv_left.setOnClickListener(new OnClickListener() {
55 |
56 | @Override
57 | public void onClick(View v) {
58 | monthDateView.onLeftClick();
59 | }
60 | });
61 |
62 | iv_right.setOnClickListener(new OnClickListener() {
63 |
64 | @Override
65 | public void onClick(View v) {
66 | monthDateView.onRightClick();
67 | }
68 | });
69 |
70 | tv_today.setOnClickListener(new OnClickListener() {
71 |
72 | @Override
73 | public void onClick(View v) {
74 | monthDateView.setTodayToView();
75 | }
76 | });
77 | }
78 |
79 |
80 | /**
81 | * 设置有事务的号码
82 | * @param listDayAndPrice
83 | */
84 | public void setListDayAndPrice(List listDayAndPrice) {
85 | this.listDayAndPrice = listDayAndPrice;
86 | monthDateView.setDayAndPriceList(listDayAndPrice);
87 | }
88 | /**
89 | * 设置哪天是休息天的号码
90 | * @param listWorkOrRelax
91 | */
92 | public void setListWorkOrRelax(List listWorkOrRelax) {
93 | this.listWorkOrRelax = listWorkOrRelax;
94 | monthDateView.setDaysWorkOrRelaxList(listWorkOrRelax);
95 | }
96 |
97 | /**
98 | * 获取所选择的年份
99 | * @return
100 | */
101 | public int getSelectYear(){
102 | return monthDateView.getmSelYear();
103 | }
104 |
105 | /**
106 | * 获取所选择的月份
107 | * @return
108 | */
109 | public int getSelectMonth(){
110 | return monthDateView.getmSelMonth();
111 | }
112 | /**
113 | * 获取所选择的日期
114 | * @return
115 | */
116 | public int getSelectDay(){
117 | return monthDateView.getmSelDay();
118 | }
119 |
120 | /**
121 | * 设置日期的click事件
122 | * @param dateViewClick
123 | */
124 | public void setDateViewClick(DateViewClick dateViewClick) {
125 | this.dateViewClick = dateViewClick;
126 | }
127 | public interface DateViewClick{
128 | public void dateClick();
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/DateUtils.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import java.util.Calendar;
4 |
5 | import android.util.Log;
6 |
7 | public class DateUtils {
8 | /**
9 | * 通过年份和月份 得到当月的日子
10 | *
11 | * @param year
12 | * @param month
13 | * @return
14 | */
15 | public static int getMonthDays(int year, int month) {
16 | month++;
17 | switch (month) {
18 | case 1:
19 | case 3:
20 | case 5:
21 | case 7:
22 | case 8:
23 | case 10:
24 | case 12:
25 | return 31;
26 | case 4:
27 | case 6:
28 | case 9:
29 | case 11:
30 | return 30;
31 | case 2:
32 | if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
33 | return 29;
34 | }else{
35 | return 28;
36 | }
37 | default:
38 | return -1;
39 | }
40 | }
41 | /**
42 | * 返回当前月份1号位于周几
43 | * @param year
44 | * 年份
45 | * @param month
46 | * 月份,传入系统获取的,不需要正常的
47 | * @return
48 | * 日:1 一:2 二:3 三:4 四:5 五:6 六:7
49 | */
50 | public static int getFirstDayWeek(int year, int month){
51 | Calendar calendar = Calendar.getInstance();
52 | calendar.set(year, month, 1);
53 | Log.d("DateView", "DateView:First:" + calendar.getFirstDayOfWeek());
54 | return calendar.get(Calendar.DAY_OF_WEEK);
55 | }
56 |
57 | /**
58 | * 根据列明获取周
59 | * @param column
60 | * @return
61 | */
62 | public static String getWeekName(int column){
63 | switch(column){
64 | case 0:
65 | return "周日";
66 | case 1:
67 | return "周一";
68 | case 2:
69 | return "周二";
70 | case 3:
71 | return "周三";
72 | case 4:
73 | return "周四";
74 | case 5:
75 | return "周五";
76 | case 6:
77 | return "周六";
78 | default :
79 | return "";
80 | }
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/DayAndPrice.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | public class DayAndPrice {
4 | public String price;
5 | public int day;
6 | public int year;
7 | public int month;
8 | public DayAndPrice(String price, int year, int month,int day) {
9 | super();
10 | this.price = price;
11 | this.day = day;
12 | this.year = year;
13 | this.month = month;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/GregorianUtil.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import java.util.Calendar;
4 | /**
5 | * 对公历日期的处理类
6 | */
7 | public class GregorianUtil {
8 | private final static String[][] GRE_FESTVIAL = {
9 | // 一月
10 | { "元旦", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
11 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
12 | // 二月
13 | { "", "", "", "", "", "", "", "", "", "", "", "", "", "情人节", "", "",
14 | "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
15 | // 三月
16 | { "", "", "", "", "", "", "", "妇女节", "", "", "", "植树节", "", "", "",
17 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
18 | "" },
19 | // 四月
20 | { "愚人节", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
21 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
22 | // 五月
23 | { "劳动节", "", "", "青年节", "", "", "", "", "", "", "", "", "", "", "",
24 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
25 | "" },
26 | // 六月
27 | { "儿童节", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
28 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
29 | // 七月
30 | { "建党节", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
31 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
32 | // 八月
33 | { "建军节", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
34 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
35 | // 九月
36 | { "", "", "", "", "", "", "", "", "", "教师节", "", "", "", "", "", "",
37 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
38 | // 十月
39 | { "国庆节", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
40 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
41 | // 十一月
42 | { "", "", "", "", "", "", "", "", "", "", "光棍节", "", "", "", "", "",
43 | "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" },
44 | // 十二月
45 | { "艾滋病", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
46 | "", "", "", "", "", "", "", "", "", "圣诞节", "", "", "", "",
47 | "", "" }, };
48 | private int mMonth;
49 | private int mDay;
50 |
51 | public GregorianUtil(Calendar calendar) {
52 | mMonth = calendar.get(Calendar.MONTH);
53 | mDay = calendar.get(Calendar.DATE);
54 | }
55 |
56 | public String getGremessage() {
57 | return GRE_FESTVIAL[mMonth][mDay - 1];
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/MonthDateView.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import java.text.DateFormat;
4 | import java.text.ParseException;
5 | import java.text.SimpleDateFormat;
6 | import java.util.ArrayList;
7 | import java.util.Calendar;
8 | import java.util.Date;
9 | import java.util.List;
10 |
11 | import com.dsw.calendarview.R;
12 |
13 | import android.content.Context;
14 | import android.content.res.TypedArray;
15 | import android.graphics.Canvas;
16 | import android.graphics.Color;
17 | import android.graphics.Paint;
18 | import android.graphics.Paint.Style;
19 | import android.graphics.Path;
20 | import android.text.TextUtils;
21 | import android.util.AttributeSet;
22 | import android.view.MotionEvent;
23 | import android.view.View;
24 | import android.view.ViewConfiguration;
25 | import android.widget.TextView;
26 |
27 | public class MonthDateView extends View {
28 | private final int NUM_COLUMNS = 7;
29 | private int NUM_ROWS = 6;
30 | private Paint mPaint;
31 | private int mSelectDayColor = Color.parseColor("#FFFFFF");
32 | private int mSelectBGColor;
33 | private int mCurrentColor;
34 | private int mCircleColor;
35 | private int mEnableDateColor;
36 | private int mUnableDateColor;
37 | private int mRelaxColor;
38 | private int mWorkColor;
39 | private int mPriceColor;
40 | private int mDateHeight;
41 | private int mCurrYear,mCurrMonth,mCurrDay;
42 | private int mSelYear,mSelMonth,mSelDay;
43 | private float mColumnSize,mRowSize;
44 | private int mDaySize,mPriceSize;
45 | private TextView tv_date,tv_week;
46 | private int weekRow;
47 | private int [][] daysString;
48 | private int mCircleRadius = 6;
49 | private DateClick dateClick;
50 | private int mMarginSize =1;
51 | private int minYear,minMonth,minDay,maxYear,maxMonth;
52 | //记录是否为国家房顶假日
53 | private List daysWorkOrRelaxList = new ArrayList();
54 | //DayAndPrice实体集合,用于存储指定日期的价格
55 | private List dayAndPriceList = new ArrayList();
56 | private int mTouchSlop;
57 | public MonthDateView(Context context, AttributeSet attrs) {
58 | super(context, attrs);
59 | TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.CalendarView);
60 | mEnableDateColor = typedArray.getColor(R.styleable.CalendarView_EnableDateColor, Color.parseColor("#000000"));
61 | mUnableDateColor = typedArray.getColor(R.styleable.CalendarView_UnableDateColor, Color.parseColor("#CBCBCB"));
62 | mCircleColor = typedArray.getColor(R.styleable.CalendarView_CircleColor, Color.parseColor("#68CB00"));
63 | mRelaxColor = typedArray.getColor(R.styleable.CalendarView_RelaxColor, Color.parseColor("#65CD00"));
64 | mWorkColor = typedArray.getColor(R.styleable.CalendarView_WorkColor, Color.parseColor("#FF9B12"));
65 | mPriceColor = typedArray.getColor(R.styleable.CalendarView_PriceColor, Color.parseColor("#FF9B12"));
66 | mSelectBGColor = typedArray.getColor(R.styleable.CalendarView_SelectBGColor, Color.parseColor("#13A4D3"));
67 | mCurrentColor = typedArray.getColor(R.styleable.CalendarView_CurrentColor, Color.parseColor("#FF0000"));
68 | mDateHeight = (int) typedArray.getDimension(R.styleable.CalendarView_DateHeight, 66);
69 | mDaySize = (int) typedArray.getDimension(R.styleable.CalendarView_DateSize, 15);
70 | mPriceSize = (int) typedArray.getDimension(R.styleable.CalendarView_PriceSize, 12);
71 | typedArray.recycle();
72 | Calendar calendar = Calendar.getInstance();
73 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
74 | mCurrYear = calendar.get(Calendar.YEAR);
75 | mCurrMonth = calendar.get(Calendar.MONTH);
76 | mCurrDay = calendar.get(Calendar.DATE);
77 | mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
78 | mRowSize = mDateHeight;
79 | setSelectYearMonthDate(mCurrYear,mCurrMonth);
80 | }
81 |
82 | @Override
83 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
84 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
85 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
86 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
87 | if(widthMode == MeasureSpec.AT_MOST){
88 | widthSize = (int) (300 * getResources().getDisplayMetrics().density);
89 | }
90 | NUM_ROWS = getMonthRowNumber();
91 | heightSize = NUM_ROWS * mDateHeight;
92 | setMeasuredDimension(widthSize, heightSize);
93 | }
94 |
95 | @Override
96 | protected void onDraw(Canvas canvas) {
97 | initSize();
98 | daysString = new int[6][7];
99 | String dayString;
100 | int mMonthDays = DateUtils.getMonthDays(mSelYear, mSelMonth);
101 | int weekNumber = DateUtils.getFirstDayWeek(mSelYear, mSelMonth);
102 | int column,row = 0;
103 | //绘制线条
104 | drawLines(canvas);
105 | for(int day = 0;day < mMonthDays;day++){
106 | dayString = (day + 1) + "";
107 | column = (day+weekNumber - 1) % 7;
108 | row = (day+weekNumber - 1) / 7;
109 | daysString[row][column]=day + 1;
110 | //判断是否为节假日
111 | String holiday = getHoliday(day + 1).trim();
112 | if(TextUtils.isEmpty(holiday)){
113 | holiday = dayString;
114 | }
115 |
116 | mPaint.setTextSize(mDaySize);
117 | float startX = mColumnSize * column + (mColumnSize - mPaint.measureText(holiday))/2;
118 | float startY = mRowSize * row + mRowSize/2 - (mPaint.ascent() + mPaint.descent())/2;
119 |
120 | //绘制背景白块
121 | if(!TextUtils.isEmpty(isdayAndPriceList(day + 1))){
122 | //绘制背景色矩形
123 | float startRecX = mColumnSize * column + mMarginSize;
124 | float startRecY = mRowSize * row + mMarginSize;
125 | float endRecX = startRecX + mColumnSize - 2 * mMarginSize;
126 | float endRecY = startRecY + mRowSize - 2 *mMarginSize;
127 | mPaint.setColor(mSelectDayColor);
128 | mPaint.setStyle(Style.FILL);
129 | canvas.drawRect(startRecX, startRecY, endRecX, endRecY, mPaint);
130 | }
131 |
132 | if(dayString.equals(mSelDay+"")){
133 | //绘制背景色矩形
134 | float startRecX = mColumnSize * column + mMarginSize;
135 | float startRecY = mRowSize * row + mMarginSize;
136 | float endRecX = startRecX + mColumnSize - 2 * mMarginSize;
137 | float endRecY = startRecY + mRowSize - 2 *mMarginSize;
138 | mPaint.setColor(mSelectBGColor);
139 | mPaint.setStyle(Style.FILL);
140 | canvas.drawRect(startRecX, startRecY, endRecX, endRecY, mPaint);
141 | //记录第几行,即第几周
142 | weekRow = column;
143 | }
144 | //绘制事务圆形标志
145 | drawCircle(row,column,day + 1,canvas);
146 | //绘制休、上班
147 | drawWorkOrRelax(row,column,day + 1,canvas);
148 | mPaint.setStyle(Style.STROKE);
149 | if(dayString.equals(mSelDay+"")){
150 | String price = isdayAndPriceList(day+1);
151 | if(!TextUtils.isEmpty(price)){
152 | int dateY = (int) (startY - 15);
153 | mPaint.setColor(mSelectDayColor);
154 | canvas.drawText(holiday, startX, dateY, mPaint);
155 |
156 | mPaint.setTextSize(mPriceSize);
157 | int priceX = (int) (mColumnSize * column + (mColumnSize - mPaint.measureText(price))/2);
158 | int priceY = (int) (startY + 15);
159 | canvas.drawText(price, priceX, priceY, mPaint);
160 | continue;
161 | }else{
162 | mPaint.setColor(mSelectDayColor);
163 | }
164 | }else if(dayString.equals(mCurrDay+"") && mCurrDay != mSelDay && mCurrMonth == mSelMonth){
165 | //正常月,选中其他日期,则今日为红色
166 | mPaint.setColor(mCurrentColor);
167 | }else{
168 | String price = isdayAndPriceList(day+1);
169 | if(!TextUtils.isEmpty(price)){
170 | int dateY = (int) (startY - 15);
171 | mPaint.setColor(mEnableDateColor);
172 | canvas.drawText(holiday, startX, dateY, mPaint);
173 |
174 | mPaint.setTextSize(mPriceSize);
175 | mPaint.setColor(mPriceColor);
176 | int priceX = (int) (mColumnSize * column + Math.abs((mColumnSize - mPaint.measureText(price))/2));
177 | int priceY = (int) (startY + 15);
178 | canvas.drawText(price, priceX, priceY, mPaint);
179 | continue;
180 | }else{
181 | mPaint.setColor(mUnableDateColor);
182 | }
183 | }
184 | canvas.drawText(holiday, startX, startY, mPaint);
185 | }
186 | if(tv_date != null){
187 | tv_date.setText(mSelYear + "年" + (mSelMonth + 1) + "月");
188 | }
189 |
190 | if(tv_week != null){
191 | tv_week.setText((mSelMonth + 1) + "月" + mSelDay + "日" + " " + DateUtils.getWeekName(weekRow));
192 | }
193 | }
194 | /**
195 | *获取节气节日
196 | * @param day
197 | * @return
198 | */
199 | private String getHoliday(int day){
200 | Calendar calendar = Calendar.getInstance();
201 | DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
202 | try {
203 | Date myDate1 = dateFormat1.parse(mSelYear + "-" + (mSelMonth+1) + "-" +day);
204 | calendar.setTime(myDate1);
205 | } catch (ParseException e) {
206 | e.printStackTrace();
207 | }
208 |
209 | return new CalendarUtil(calendar).getHolidayMsg();
210 | }
211 |
212 | /**
213 | * 判断是否为事务天数,通过获取price来辨别
214 | * @param day
215 | * @return
216 | */
217 | private String isdayAndPriceList(int day){
218 | if(dayAndPriceList == null || dayAndPriceList.size() == 0)return "";
219 | DayAndPrice dayAndPrice;
220 | for(int index = 0;index < dayAndPriceList.size();index++){
221 | dayAndPrice = dayAndPriceList.get(index);
222 | if(dayAndPrice.day == day && dayAndPrice.month == mSelMonth + 1 && dayAndPrice.year == mSelYear){
223 | return dayAndPrice.price;
224 | }
225 | }
226 | return "";
227 | }
228 |
229 | /**
230 | * 绘制事务圆形
231 | * @param row
232 | * @param column
233 | * @param day
234 | * @param canvas
235 | */
236 | private void drawCircle(int row,int column,int day,Canvas canvas){
237 | if(dayAndPriceList != null && dayAndPriceList.size() >0){
238 | if(TextUtils.isEmpty(isdayAndPriceList(day)))return;
239 | mPaint.setColor(mCircleColor);
240 | mPaint.setStyle(Style.FILL);
241 | float circleX = (float) (mColumnSize * column + mColumnSize*0.8);
242 | float circley = (float) (mRowSize * row + mRowSize*0.2);
243 | canvas.drawCircle(circleX, circley, mCircleRadius, mPaint);
244 | }
245 | }
246 |
247 | /**
248 | * 绘制休息天
249 | * @param row
250 | * @param column
251 | * @param day
252 | * @param canvas
253 | */
254 | private void drawWorkOrRelax(int row,int column,int day,Canvas canvas){
255 | if(daysWorkOrRelaxList != null && daysWorkOrRelaxList.size() > 0){
256 | WorkOrRelax workOrRelax;
257 | for(int i=0;i 0 && Math.abs(upX-downX) > mTouchSlop){//左滑
347 | onLeftClick();
348 | }else if(upX-downX < 0 && Math.abs(upX-downX) > mTouchSlop){//右滑
349 | onRightClick();
350 | }
351 | if(Math.abs(upX-downX) < 10 && Math.abs(upY - downY) < 10){//点击事件
352 | performClick();
353 | doClickAction((upX + downX)/2,(upY + downY)/2);
354 | }
355 | break;
356 | }
357 | return true;
358 | }
359 |
360 | /**
361 | * 初始化列宽行高
362 | */
363 | private void initSize(){
364 | mColumnSize = getWidth() *1.0F/ NUM_COLUMNS;
365 | }
366 |
367 | /**
368 | * 获取总共行数
369 | * @return
370 | */
371 | private int getMonthRowNumber(){
372 | int mMonthDays = DateUtils.getMonthDays(mSelYear, mSelMonth);
373 | int weekNumber = DateUtils.getFirstDayWeek(mSelYear, mSelMonth);
374 | return (mMonthDays + weekNumber - 1) % 7 == 0 ? (mMonthDays + weekNumber - 1) / 7 : (mMonthDays + weekNumber - 1) / 7 + 1;
375 | }
376 |
377 | /**
378 | * 设置年月
379 | * @param year
380 | * @param month
381 | */
382 | private void setSelectYearMonth(int year,int month,int day){
383 | if(year <=0 || month <=0 || day <= 0)return;
384 | mSelYear = year;
385 | mSelMonth = month;
386 | mSelDay = day;
387 | }
388 |
389 | /**
390 | * 设置选中的月份
391 | * @param year
392 | * @param month
393 | */
394 | private void setSelectYearMonthDate(int year,int month){
395 | mSelYear = year;
396 | mSelMonth = month;
397 | }
398 |
399 | /**
400 | * 执行点击事件
401 | * @param x
402 | * @param y
403 | */
404 | private void doClickAction(int x,int y){
405 | int row = (int) (y / mRowSize);
406 | int column = (int) (x / mColumnSize);
407 | if(TextUtils.isEmpty(isdayAndPriceList(daysString[row][column])))return;
408 | setSelectYearMonth(mSelYear,mSelMonth,daysString[row][column]);
409 | invalidate();
410 | //执行activity发送过来的点击处理事件
411 | if(dateClick != null){
412 | dateClick.onClickOnDate();
413 | }
414 | }
415 |
416 | /**
417 | * 左点击,日历向后翻页
418 | */
419 | public void onLeftClick(){
420 | if(minYear == mSelYear && minMonth == mSelMonth + 1)return;
421 | int year = mSelYear;
422 | int month = mSelMonth;
423 | int day = mSelDay;
424 | if(month == 0){//若果是1月份,则变成12月份
425 | year = mSelYear-1;
426 | month = 11;
427 | }else if(DateUtils.getMonthDays(year, month) == day){
428 | //如果当前日期为该月最后一点,当向前推的时候,就需要改变选中的日期
429 | month = month-1;
430 | day = DateUtils.getMonthDays(year, month);
431 | }else{
432 | month = month-1;
433 | }
434 | setSelectYearMonth(year,month,getMinDayOfMonth(month));
435 | forceLayout();
436 | measure(0, 0);
437 | requestLayout();
438 | invalidate();
439 | }
440 |
441 | /**
442 | * 右点击,日历向前翻页
443 | */
444 | public void onRightClick(){
445 | if(maxYear == mSelYear && maxMonth == mSelMonth + 1)return;
446 | int year = mSelYear;
447 | int month = mSelMonth;
448 | int day = mSelDay;
449 | if(month == 11){//若果是12月份,则变成1月份
450 | year = mSelYear+1;
451 | month = 0;
452 | }else if(DateUtils.getMonthDays(year, month) == day){
453 | //如果当前日期为该月最后一点,当向前推的时候,就需要改变选中的日期
454 | month = month + 1;
455 | day = DateUtils.getMonthDays(year, month);
456 | }else{
457 | month = month + 1;
458 | }
459 | setSelectYearMonth(year,month,getMinDayOfMonth(month));
460 | forceLayout();
461 | measure(0, 0);
462 | requestLayout();
463 | invalidate();
464 | }
465 | /**
466 | * 获取事务月份最小的月号
467 | * @param month
468 | * @return
469 | */
470 | private int getMinDayOfMonth(int month){
471 | if(dayAndPriceList == null || dayAndPriceList.size() == 0)return -1;
472 | int day = 32;
473 | DayAndPrice dayAndPrice;
474 | for(int i = 0;i dayAndPrice.day){
478 | day = dayAndPrice.day;
479 | }
480 | }
481 | }
482 | return day;
483 | }
484 |
485 | /**
486 | * 获取选择的年份
487 | * @return
488 | */
489 | public int getmSelYear() {
490 | return mSelYear;
491 | }
492 | /**
493 | * 获取选择的月份
494 | * @return
495 | */
496 | public int getmSelMonth() {
497 | return mSelMonth;
498 | }
499 | /**
500 | * 获取选择的日期
501 | * @param mSelDay
502 | */
503 | public int getmSelDay() {
504 | return this.mSelDay;
505 | }
506 |
507 | /**
508 | * 选择日期的颜色,默认为白色
509 | * @param mSelectDayColor
510 | */
511 | public void setmSelectDayColor(int mSelectDayColor) {
512 | this.mSelectDayColor = mSelectDayColor;
513 | }
514 |
515 | /**
516 | * 选中日期的背景颜色,默认蓝色
517 | * @param mSelectBGColor
518 | */
519 | public void setmSelectBGColor(int mSelectBGColor) {
520 | this.mSelectBGColor = mSelectBGColor;
521 | }
522 | /**
523 | * 当前日期不是选中的颜色,默认红色
524 | * @param mCurrentColor
525 | */
526 | public void setmCurrentColor(int mCurrentColor) {
527 | this.mCurrentColor = mCurrentColor;
528 | }
529 |
530 | /**
531 | * 日期的大小,默认18sp
532 | * @param mDaySize
533 | */
534 | public void setmDaySize(int mDaySize) {
535 | this.mDaySize = mDaySize;
536 | }
537 | /**
538 | * 设置显示当前日期的控件
539 | * @param tv_date
540 | * 显示日期
541 | * @param tv_week
542 | * 显示周
543 | */
544 | public void setTextView(TextView tv_date,TextView tv_week){
545 | this.tv_date = tv_date;
546 | this.tv_week = tv_week;
547 | invalidate();
548 | }
549 |
550 | /**
551 | * 设置休班天数
552 | * @param daysWorkOrRelaxList
553 | */
554 | public void setDaysWorkOrRelaxList(List daysWorkOrRelaxList) {
555 | this.daysWorkOrRelaxList = daysWorkOrRelaxList;
556 | }
557 |
558 | /**
559 | * 设置有价格的日期
560 | * @param dayAndPriceList
561 | */
562 | public void setDayAndPriceList(List dayAndPriceList) {
563 | this.dayAndPriceList = dayAndPriceList;
564 | //跳转到有业务数据的月份
565 | goThingMonth(dayAndPriceList);
566 | setSelectYearMonth(minYear,minMonth-1,minDay);
567 | }
568 |
569 | /**
570 | * 获取事务数据最小的年月
571 | * @param dayAndPriceList
572 | */
573 | private void goThingMonth(List dayAndPriceList){
574 | if(dayAndPriceList == null || dayAndPriceList.size() == 0)return;
575 | minYear = dayAndPriceList.get(0).year;
576 | minMonth = dayAndPriceList.get(0).month;
577 | minDay = dayAndPriceList.get(0).day;
578 | DayAndPrice dayAndPrice;
579 | for(int i = 0;i dayAndPrice.year){
582 | minYear = dayAndPrice.year;
583 | minMonth = dayAndPrice.month;
584 | }else if(minYear == dayAndPrice.year){
585 | if(minMonth > dayAndPrice.month){
586 | minMonth = dayAndPrice.month;
587 | }else if(minMonth == dayAndPrice.month){
588 | if(minDay > dayAndPrice.day){
589 | minDay = dayAndPrice.day;
590 | }
591 | }
592 | }
593 |
594 | if(maxYear < dayAndPrice.year){
595 | maxYear = dayAndPrice.year;
596 | maxMonth = dayAndPrice.month;
597 | }else if(maxYear == dayAndPrice.year){
598 | if(maxMonth < dayAndPrice.month){
599 | maxMonth = dayAndPrice.month;
600 | }
601 | }
602 | }
603 | }
604 |
605 | /***
606 | * 设置圆圈的半径,默认为6
607 | * @param mCircleRadius
608 | */
609 | public void setmCircleRadius(int mCircleRadius) {
610 | this.mCircleRadius = mCircleRadius;
611 | }
612 |
613 | /**
614 | * 设置圆圈的半径
615 | * @param mCircleColor
616 | */
617 | public void setmCircleColor(int mCircleColor) {
618 | this.mCircleColor = mCircleColor;
619 | }
620 |
621 | /**
622 | * 设置日期的点击回调事件
623 | * @author shiwei.deng
624 | *
625 | */
626 | public interface DateClick{
627 | public void onClickOnDate();
628 | }
629 |
630 | /**
631 | * 设置日期点击事件
632 | * @param dateClick
633 | */
634 | public void setDateClick(DateClick dateClick) {
635 | this.dateClick = dateClick;
636 | }
637 |
638 | /**
639 | * 跳转至今天
640 | */
641 | public void setTodayToView(){
642 | setSelectYearMonth(mCurrYear,mCurrMonth,mCurrDay);
643 | invalidate();
644 | }
645 | }
646 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/SolarTermsUtil.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import java.util.Calendar;
4 |
5 |
6 | /**
7 | * 主要用于把公历日期处理成24节气
8 | */
9 | public class SolarTermsUtil {
10 | /**
11 | * 计算得到公历的年份
12 | */
13 | private int gregorianYear;
14 |
15 | /**
16 | * 计算得到公历的月份
17 | */
18 | private int gregorianMonth;
19 |
20 | /**
21 | * 用于计算得到公历的日期
22 | */
23 | private int gregorianDate;
24 |
25 | private int chineseYear;
26 | private int chineseMonth;
27 | private int chineseDate;
28 |
29 | // 初始日,公历农历对应日期:
30 | // 公历 1901 年 1 月 1 日,对应农历 4598 年 11 月 11 日
31 | private static int baseYear = 1901;
32 | private static int baseMonth = 1;
33 | private static int baseDate = 1;
34 | private static int baseIndex = 0;
35 | private static int baseChineseYear = 4598 - 1;
36 | private static int baseChineseMonth = 11;
37 | private static int baseChineseDate = 11;
38 | private static char[] daysInGregorianMonth = { 31, 28, 31, 30, 31, 30, 31,
39 | 31, 30, 31, 30, 31 };
40 |
41 | private int sectionalTerm;
42 | private int principleTerm;
43 |
44 | private static char[][] sectionalTermMap = {
45 | { 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6, 5, 5, 6, 6, 5, 5, 5, 5, 5,
46 | 5, 5, 5, 4, 5, 5 },
47 | { 5, 4, 5, 5, 5, 4, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 3,
48 | 3, 4, 4, 3, 3, 3 },
49 | { 6, 6, 6, 7, 6, 6, 6, 6, 5, 6, 6, 6, 5, 5, 6, 6, 5, 5, 5, 6, 5, 5,
50 | 5, 5, 4, 5, 5, 5, 5 },
51 | { 5, 5, 6, 6, 5, 5, 5, 6, 5, 5, 5, 5, 4, 5, 5, 5, 4, 4, 5, 5, 4, 4,
52 | 4, 5, 4, 4, 4, 4, 5 },
53 | { 6, 6, 6, 7, 6, 6, 6, 6, 5, 6, 6, 6, 5, 5, 6, 6, 5, 5, 5, 6, 5, 5,
54 | 5, 5, 4, 5, 5, 5, 5 },
55 | { 6, 6, 7, 7, 6, 6, 6, 7, 6, 6, 6, 6, 5, 6, 6, 6, 5, 5, 6, 6, 5, 5,
56 | 5, 6, 5, 5, 5, 5, 4, 5, 5, 5, 5 },
57 | { 7, 8, 8, 8, 7, 7, 8, 8, 7, 7, 7, 8, 7, 7, 7, 7, 6, 7, 7, 7, 6, 6,
58 | 7, 7, 6, 6, 6, 7, 7 },
59 | { 8, 8, 8, 9, 8, 8, 8, 8, 7, 8, 8, 8, 7, 7, 8, 8, 7, 7, 7, 8, 7, 7,
60 | 7, 7, 6, 7, 7, 7, 6, 6, 7, 7, 7 },
61 | { 8, 8, 8, 9, 8, 8, 8, 8, 7, 8, 8, 8, 7, 7, 8, 8, 7, 7, 7, 8, 7, 7,
62 | 7, 7, 6, 7, 7, 7, 7 },
63 | { 9, 9, 9, 9, 8, 9, 9, 9, 8, 8, 9, 9, 8, 8, 8, 9, 8, 8, 8, 8, 7, 8,
64 | 8, 8, 7, 7, 8, 8, 8 },
65 | { 8, 8, 8, 8, 7, 8, 8, 8, 7, 7, 8, 8, 7, 7, 7, 8, 7, 7, 7, 7, 6, 7,
66 | 7, 7, 6, 6, 7, 7, 7 },
67 | { 7, 8, 8, 8, 7, 7, 8, 8, 7, 7, 7, 8, 7, 7, 7, 7, 6, 7, 7, 7, 6, 6,
68 | 7, 7, 6, 6, 6, 7, 7 } };
69 | private static char[][] sectionalTermYear = {
70 | { 13, 49, 85, 117, 149, 185, 201, 250, 250 },
71 | { 13, 45, 81, 117, 149, 185, 201, 250, 250 },
72 | { 13, 48, 84, 112, 148, 184, 200, 201, 250 },
73 | { 13, 45, 76, 108, 140, 172, 200, 201, 250 },
74 | { 13, 44, 72, 104, 132, 168, 200, 201, 250 },
75 | { 5, 33, 68, 96, 124, 152, 188, 200, 201 },
76 | { 29, 57, 85, 120, 148, 176, 200, 201, 250 },
77 | { 13, 48, 76, 104, 132, 168, 196, 200, 201 },
78 | { 25, 60, 88, 120, 148, 184, 200, 201, 250 },
79 | { 16, 44, 76, 108, 144, 172, 200, 201, 250 },
80 | { 28, 60, 92, 124, 160, 192, 200, 201, 250 },
81 | { 17, 53, 85, 124, 156, 188, 200, 201, 250 } };
82 | private static char[][] principleTermMap = {
83 | { 21, 21, 21, 21, 21, 20, 21, 21, 21, 20, 20, 21, 21, 20, 20, 20,
84 | 20, 20, 20, 20, 20, 19, 20, 20, 20, 19, 19, 20 },
85 | { 20, 19, 19, 20, 20, 19, 19, 19, 19, 19, 19, 19, 19, 18, 19, 19,
86 | 19, 18, 18, 19, 19, 18, 18, 18, 18, 18, 18, 18 },
87 | { 21, 21, 21, 22, 21, 21, 21, 21, 20, 21, 21, 21, 20, 20, 21, 21,
88 | 20, 20, 20, 21, 20, 20, 20, 20, 19, 20, 20, 20, 20 },
89 | { 20, 21, 21, 21, 20, 20, 21, 21, 20, 20, 20, 21, 20, 20, 20, 20,
90 | 19, 20, 20, 20, 19, 19, 20, 20, 19, 19, 19, 20, 20 },
91 | { 21, 22, 22, 22, 21, 21, 22, 22, 21, 21, 21, 22, 21, 21, 21, 21,
92 | 20, 21, 21, 21, 20, 20, 21, 21, 20, 20, 20, 21, 21 },
93 | { 22, 22, 22, 22, 21, 22, 22, 22, 21, 21, 22, 22, 21, 21, 21, 22,
94 | 21, 21, 21, 21, 20, 21, 21, 21, 20, 20, 21, 21, 21 },
95 | { 23, 23, 24, 24, 23, 23, 23, 24, 23, 23, 23, 23, 22, 23, 23, 23,
96 | 22, 22, 23, 23, 22, 22, 22, 23, 22, 22, 22, 22, 23 },
97 | { 23, 24, 24, 24, 23, 23, 24, 24, 23, 23, 23, 24, 23, 23, 23, 23,
98 | 22, 23, 23, 23, 22, 22, 23, 23, 22, 22, 22, 23, 23 },
99 | { 23, 24, 24, 24, 23, 23, 24, 24, 23, 23, 23, 24, 23, 23, 23, 23,
100 | 22, 23, 23, 23, 22, 22, 23, 23, 22, 22, 22, 23, 23 },
101 | { 24, 24, 24, 24, 23, 24, 24, 24, 23, 23, 24, 24, 23, 23, 23, 24,
102 | 23, 23, 23, 23, 22, 23, 23, 23, 22, 22, 23, 23, 23 },
103 | { 23, 23, 23, 23, 22, 23, 23, 23, 22, 22, 23, 23, 22, 22, 22, 23,
104 | 22, 22, 22, 22, 21, 22, 22, 22, 21, 21, 22, 22, 22 },
105 | { 22, 22, 23, 23, 22, 22, 22, 23, 22, 22, 22, 22, 21, 22, 22, 22,
106 | 21, 21, 22, 22, 21, 21, 21, 22, 21, 21, 21, 21, 22 } };
107 | private static char[][] principleTermYear = {
108 | { 13, 45, 81, 113, 149, 185, 201 },
109 | { 21, 57, 93, 125, 161, 193, 201 },
110 | { 21, 56, 88, 120, 152, 188, 200, 201 },
111 | { 21, 49, 81, 116, 144, 176, 200, 201 },
112 | { 17, 49, 77, 112, 140, 168, 200, 201 },
113 | { 28, 60, 88, 116, 148, 180, 200, 201 },
114 | { 25, 53, 84, 112, 144, 172, 200, 201 },
115 | { 29, 57, 89, 120, 148, 180, 200, 201 },
116 | { 17, 45, 73, 108, 140, 168, 200, 201 },
117 | { 28, 60, 92, 124, 160, 192, 200, 201 },
118 | { 16, 44, 80, 112, 148, 180, 200, 201 },
119 | { 17, 53, 88, 120, 156, 188, 200, 201 } };
120 |
121 | private static char[] chineseMonths = {
122 | // 农历月份大小压缩表,两个字节表示一年。两个字节共十六个二进制位数,
123 | // 前四个位数表示闰月月份,后十二个位数表示十二个农历月份的大小。
124 | 0x00, 0x04, 0xad, 0x08, 0x5a, 0x01, 0xd5, 0x54, 0xb4, 0x09, 0x64,
125 | 0x05, 0x59, 0x45, 0x95, 0x0a, 0xa6, 0x04, 0x55, 0x24, 0xad, 0x08,
126 | 0x5a, 0x62, 0xda, 0x04, 0xb4, 0x05, 0xb4, 0x55, 0x52, 0x0d, 0x94,
127 | 0x0a, 0x4a, 0x2a, 0x56, 0x02, 0x6d, 0x71, 0x6d, 0x01, 0xda, 0x02,
128 | 0xd2, 0x52, 0xa9, 0x05, 0x49, 0x0d, 0x2a, 0x45, 0x2b, 0x09, 0x56,
129 | 0x01, 0xb5, 0x20, 0x6d, 0x01, 0x59, 0x69, 0xd4, 0x0a, 0xa8, 0x05,
130 | 0xa9, 0x56, 0xa5, 0x04, 0x2b, 0x09, 0x9e, 0x38, 0xb6, 0x08, 0xec,
131 | 0x74, 0x6c, 0x05, 0xd4, 0x0a, 0xe4, 0x6a, 0x52, 0x05, 0x95, 0x0a,
132 | 0x5a, 0x42, 0x5b, 0x04, 0xb6, 0x04, 0xb4, 0x22, 0x6a, 0x05, 0x52,
133 | 0x75, 0xc9, 0x0a, 0x52, 0x05, 0x35, 0x55, 0x4d, 0x0a, 0x5a, 0x02,
134 | 0x5d, 0x31, 0xb5, 0x02, 0x6a, 0x8a, 0x68, 0x05, 0xa9, 0x0a, 0x8a,
135 | 0x6a, 0x2a, 0x05, 0x2d, 0x09, 0xaa, 0x48, 0x5a, 0x01, 0xb5, 0x09,
136 | 0xb0, 0x39, 0x64, 0x05, 0x25, 0x75, 0x95, 0x0a, 0x96, 0x04, 0x4d,
137 | 0x54, 0xad, 0x04, 0xda, 0x04, 0xd4, 0x44, 0xb4, 0x05, 0x54, 0x85,
138 | 0x52, 0x0d, 0x92, 0x0a, 0x56, 0x6a, 0x56, 0x02, 0x6d, 0x02, 0x6a,
139 | 0x41, 0xda, 0x02, 0xb2, 0xa1, 0xa9, 0x05, 0x49, 0x0d, 0x0a, 0x6d,
140 | 0x2a, 0x09, 0x56, 0x01, 0xad, 0x50, 0x6d, 0x01, 0xd9, 0x02, 0xd1,
141 | 0x3a, 0xa8, 0x05, 0x29, 0x85, 0xa5, 0x0c, 0x2a, 0x09, 0x96, 0x54,
142 | 0xb6, 0x08, 0x6c, 0x09, 0x64, 0x45, 0xd4, 0x0a, 0xa4, 0x05, 0x51,
143 | 0x25, 0x95, 0x0a, 0x2a, 0x72, 0x5b, 0x04, 0xb6, 0x04, 0xac, 0x52,
144 | 0x6a, 0x05, 0xd2, 0x0a, 0xa2, 0x4a, 0x4a, 0x05, 0x55, 0x94, 0x2d,
145 | 0x0a, 0x5a, 0x02, 0x75, 0x61, 0xb5, 0x02, 0x6a, 0x03, 0x61, 0x45,
146 | 0xa9, 0x0a, 0x4a, 0x05, 0x25, 0x25, 0x2d, 0x09, 0x9a, 0x68, 0xda,
147 | 0x08, 0xb4, 0x09, 0xa8, 0x59, 0x54, 0x03, 0xa5, 0x0a, 0x91, 0x3a,
148 | 0x96, 0x04, 0xad, 0xb0, 0xad, 0x04, 0xda, 0x04, 0xf4, 0x62, 0xb4,
149 | 0x05, 0x54, 0x0b, 0x44, 0x5d, 0x52, 0x0a, 0x95, 0x04, 0x55, 0x22,
150 | 0x6d, 0x02, 0x5a, 0x71, 0xda, 0x02, 0xaa, 0x05, 0xb2, 0x55, 0x49,
151 | 0x0b, 0x4a, 0x0a, 0x2d, 0x39, 0x36, 0x01, 0x6d, 0x80, 0x6d, 0x01,
152 | 0xd9, 0x02, 0xe9, 0x6a, 0xa8, 0x05, 0x29, 0x0b, 0x9a, 0x4c, 0xaa,
153 | 0x08, 0xb6, 0x08, 0xb4, 0x38, 0x6c, 0x09, 0x54, 0x75, 0xd4, 0x0a,
154 | 0xa4, 0x05, 0x45, 0x55, 0x95, 0x0a, 0x9a, 0x04, 0x55, 0x44, 0xb5,
155 | 0x04, 0x6a, 0x82, 0x6a, 0x05, 0xd2, 0x0a, 0x92, 0x6a, 0x4a, 0x05,
156 | 0x55, 0x0a, 0x2a, 0x4a, 0x5a, 0x02, 0xb5, 0x02, 0xb2, 0x31, 0x69,
157 | 0x03, 0x31, 0x73, 0xa9, 0x0a, 0x4a, 0x05, 0x2d, 0x55, 0x2d, 0x09,
158 | 0x5a, 0x01, 0xd5, 0x48, 0xb4, 0x09, 0x68, 0x89, 0x54, 0x0b, 0xa4,
159 | 0x0a, 0xa5, 0x6a, 0x95, 0x04, 0xad, 0x08, 0x6a, 0x44, 0xda, 0x04,
160 | 0x74, 0x05, 0xb0, 0x25, 0x54, 0x03 };
161 |
162 | /**
163 | * 用于保存24节气
164 | */
165 | private static String[] principleTermNames = { "大寒", "雨水", "春分", "谷雨",
166 | "小满", "夏至", "大暑", "处暑", "秋分", "霜降", "小雪", "冬至" };
167 | /**
168 | * 用于保存24节气
169 | */
170 | private static String[] sectionalTermNames = { "小寒", "立春", "惊蛰", "清明",
171 | "立夏", "芒种", "小暑", "立秋", "白露", "寒露", "立冬", "大雪" };
172 |
173 | public SolarTermsUtil(Calendar calendar) {
174 | gregorianYear = calendar.get(Calendar.YEAR);
175 | gregorianMonth = calendar.get(Calendar.MONTH) + 1;
176 | gregorianDate = calendar.get(Calendar.DATE);
177 | computeChineseFields();
178 | computeSolarTerms();
179 | }
180 |
181 | public int computeChineseFields() {
182 | if (gregorianYear < 1901 || gregorianYear > 2100)
183 | return 1;
184 | int startYear = baseYear;
185 | int startMonth = baseMonth;
186 | int startDate = baseDate;
187 | chineseYear = baseChineseYear;
188 | chineseMonth = baseChineseMonth;
189 | chineseDate = baseChineseDate;
190 | // 第二个对应日,用以提高计算效率
191 | // 公历 2000 年 1 月 1 日,对应农历 4697 年 11 月 25 日
192 | if (gregorianYear >= 2000) {
193 | startYear = baseYear + 99;
194 | startMonth = 1;
195 | startDate = 1;
196 | chineseYear = baseChineseYear + 99;
197 | chineseMonth = 11;
198 | chineseDate = 25;
199 | }
200 | int daysDiff = 0;
201 | for (int i = startYear; i < gregorianYear; i++) {
202 | daysDiff += 365;
203 | if (isGregorianLeapYear(i))
204 | daysDiff += 1; // leap year
205 | }
206 | for (int i = startMonth; i < gregorianMonth; i++) {
207 | daysDiff += daysInGregorianMonth(gregorianYear, i);
208 | }
209 | daysDiff += gregorianDate - startDate;
210 |
211 | chineseDate += daysDiff;
212 | int lastDate = daysInChineseMonth(chineseYear, chineseMonth);
213 | int nextMonth = nextChineseMonth(chineseYear, chineseMonth);
214 | while (chineseDate > lastDate) {
215 | if (Math.abs(nextMonth) < Math.abs(chineseMonth))
216 | chineseYear++;
217 | chineseMonth = nextMonth;
218 | chineseDate -= lastDate;
219 | lastDate = daysInChineseMonth(chineseYear, chineseMonth);
220 | nextMonth = nextChineseMonth(chineseYear, chineseMonth);
221 | }
222 | return 0;
223 | }
224 |
225 | public int computeSolarTerms() {
226 | if (gregorianYear < 1901 || gregorianYear > 2100)
227 | return 1;
228 | sectionalTerm = sectionalTerm(gregorianYear, gregorianMonth);
229 | principleTerm = principleTerm(gregorianYear, gregorianMonth);
230 | return 0;
231 | }
232 |
233 | public static int sectionalTerm(int y, int m) {
234 | if (y < 1901 || y > 2100)
235 | return 0;
236 | int index = 0;
237 | int ry = y - baseYear + 1;
238 | while (ry >= sectionalTermYear[m - 1][index])
239 | index++;
240 | int term = sectionalTermMap[m - 1][4 * index + ry % 4];
241 | if ((ry == 121) && (m == 4))
242 | term = 5;
243 | if ((ry == 132) && (m == 4))
244 | term = 5;
245 | if ((ry == 194) && (m == 6))
246 | term = 6;
247 | return term;
248 | }
249 |
250 | public static int principleTerm(int y, int m) {
251 | if (y < 1901 || y > 2100)
252 | return 0;
253 | int index = 0;
254 | int ry = y - baseYear + 1;
255 | while (ry >= principleTermYear[m - 1][index])
256 | index++;
257 | int term = principleTermMap[m - 1][4 * index + ry % 4];
258 | if ((ry == 171) && (m == 3))
259 | term = 21;
260 | if ((ry == 181) && (m == 5))
261 | term = 21;
262 | return term;
263 | }
264 |
265 | /**
266 | * 用于判断输入的年份是否为闰年
267 | *
268 | * @param year
269 | * 输入的年份
270 | * @return true 表示闰年
271 | */
272 | public static boolean isGregorianLeapYear(int year) {
273 | boolean isLeap = false;
274 | if (year % 4 == 0)
275 | isLeap = true;
276 | if (year % 100 == 0)
277 | isLeap = false;
278 | if (year % 400 == 0)
279 | isLeap = true;
280 | return isLeap;
281 | }
282 |
283 | public static int daysInGregorianMonth(int y, int m) {
284 | int d = daysInGregorianMonth[m - 1];
285 | if (m == 2 && isGregorianLeapYear(y))
286 | d++; // 公历闰年二月多一天
287 | return d;
288 | }
289 |
290 | public static int daysInChineseMonth(int y, int m) {
291 | // 注意:闰月 m < 0
292 | int index = y - baseChineseYear + baseIndex;
293 | int v = 0;
294 | int l = 0;
295 | int d = 30;
296 | if (1 <= m && m <= 8) {
297 | v = chineseMonths[2 * index];
298 | l = m - 1;
299 | if (((v >> l) & 0x01) == 1)
300 | d = 29;
301 | } else if (9 <= m && m <= 12) {
302 | v = chineseMonths[2 * index + 1];
303 | l = m - 9;
304 | if (((v >> l) & 0x01) == 1)
305 | d = 29;
306 | } else {
307 | v = chineseMonths[2 * index + 1];
308 | v = (v >> 4) & 0x0F;
309 | if (v != Math.abs(m)) {
310 | d = 0;
311 | } else {
312 | d = 29;
313 | for (int i = 0; i < bigLeapMonthYears.length; i++) {
314 | if (bigLeapMonthYears[i] == index) {
315 | d = 30;
316 | break;
317 | }
318 | }
319 | }
320 | }
321 | return d;
322 | }
323 |
324 | public static int nextChineseMonth(int y, int m) {
325 | int n = Math.abs(m) + 1;
326 | if (m > 0) {
327 | int index = y - baseChineseYear + baseIndex;
328 | int v = chineseMonths[2 * index + 1];
329 | v = (v >> 4) & 0x0F;
330 | if (v == m)
331 | n = -m;
332 | }
333 | if (n == 13)
334 | n = 1;
335 | return n;
336 | }
337 |
338 | // 大闰月的闰年年份
339 | private static int[] bigLeapMonthYears = { 6, 14, 19, 25, 33, 36, 38, 41,
340 | 44, 52, 55, 79, 117, 136, 147, 150, 155, 158, 185, 193 };
341 |
342 | /**
343 | * 用于获取24节气的值
344 | *
345 | * @return 24节气的值
346 | */
347 | public String getSolartermsMsg() {
348 | String str = "";
349 | String gm = String.valueOf(gregorianMonth);
350 | if (gm.length() == 1)
351 | gm = ' ' + gm;
352 | String cm = String.valueOf(Math.abs(chineseMonth));
353 | if (cm.length() == 1)
354 | cm = ' ' + cm;
355 | String gd = String.valueOf(gregorianDate);
356 | if (gd.length() == 1)
357 | gd = ' ' + gd;
358 | String cd = String.valueOf(chineseDate);
359 | if (cd.length() == 1)
360 | cd = ' ' + cd;
361 | if (gregorianDate == sectionalTerm) {
362 | str = " " + sectionalTermNames[gregorianMonth - 1];
363 | } else if (gregorianDate == principleTerm) {
364 | str = " " + principleTermNames[gregorianMonth - 1];
365 | }
366 | return str;
367 | }
368 | }
369 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/WeekDayView.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.Style;
8 | import android.util.AttributeSet;
9 | import android.util.DisplayMetrics;
10 | import android.view.View;
11 |
12 | public class WeekDayView extends View {
13 | //上横线颜色
14 | private int mTopLineColor = Color.parseColor("#CCE4F2");
15 | //下横线颜色
16 | private int mBottomLineColor = Color.parseColor("#CCE4F2");
17 | //周一到周五的颜色
18 | private int mWeedayColor = Color.parseColor("#1FC2F3");
19 | //周六、周日的颜色
20 | private int mWeekendColor = Color.parseColor("#fa4451");
21 | //线的宽度
22 | private int mStrokeWidth = 4;
23 | private int mWeekSize = 14;
24 | private Paint paint;
25 | private DisplayMetrics mDisplayMetrics;
26 | private String[] weekString = new String[]{"日","一","二","三","四","五","六"};
27 | public WeekDayView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | mDisplayMetrics = getResources().getDisplayMetrics();
30 | paint = new Paint();
31 | }
32 |
33 | @Override
34 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
35 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
36 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
37 |
38 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
39 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
40 |
41 | if(heightMode == MeasureSpec.AT_MOST){
42 | heightSize = mDisplayMetrics.densityDpi * 30;
43 | }
44 | if(widthMode == MeasureSpec.AT_MOST){
45 | widthSize = mDisplayMetrics.densityDpi * 300;
46 | }
47 | setMeasuredDimension(widthSize, heightSize);
48 | }
49 |
50 | @Override
51 | protected void onDraw(Canvas canvas) {
52 | int width = getWidth();
53 | int height = getHeight();
54 | //进行画上下线
55 | paint.setStyle(Style.STROKE);
56 | paint.setColor(mTopLineColor);
57 | paint.setStrokeWidth(mStrokeWidth);
58 | canvas.drawLine(0, 0, width, 0, paint);
59 |
60 | //画下横线
61 | paint.setColor(mBottomLineColor);
62 | canvas.drawLine(0, height, width, height, paint);
63 | paint.setStyle(Style.FILL);
64 | paint.setTextSize(mWeekSize * mDisplayMetrics.scaledDensity);
65 | int columnWidth = width / 7;
66 | for(int i=0;i < weekString.length;i++){
67 | String text = weekString[i];
68 | int fontWidth = (int) paint.measureText(text);
69 | int startX = columnWidth * i + (columnWidth - fontWidth)/2;
70 | int startY = (int) (height/2 - (paint.ascent() + paint.descent())/2);
71 | if(text.indexOf("日") > -1|| text.indexOf("六") > -1){
72 | paint.setColor(mWeekendColor);
73 | }else{
74 | paint.setColor(mWeedayColor);
75 | }
76 | canvas.drawText(text, startX, startY, paint);
77 | }
78 | }
79 |
80 | /**
81 | * 设置顶线的颜色
82 | * @param mTopLineColor
83 | */
84 | public void setmTopLineColor(int mTopLineColor) {
85 | this.mTopLineColor = mTopLineColor;
86 | }
87 |
88 | /**
89 | * 设置底线的颜色
90 | * @param mBottomLineColor
91 | */
92 | public void setmBottomLineColor(int mBottomLineColor) {
93 | this.mBottomLineColor = mBottomLineColor;
94 | }
95 |
96 | /**
97 | * 设置周一-五的颜色
98 | * @return
99 | */
100 | public void setmWeedayColor(int mWeedayColor) {
101 | this.mWeedayColor = mWeedayColor;
102 | }
103 |
104 | /**
105 | * 设置周六、周日的颜色
106 | * @param mWeekendColor
107 | */
108 | public void setmWeekendColor(int mWeekendColor) {
109 | this.mWeekendColor = mWeekendColor;
110 | }
111 |
112 | /**
113 | * 设置边线的宽度
114 | * @param mStrokeWidth
115 | */
116 | public void setmStrokeWidth(int mStrokeWidth) {
117 | this.mStrokeWidth = mStrokeWidth;
118 | }
119 |
120 |
121 | /**
122 | * 设置字体的大小
123 | * @param mWeekSize
124 | */
125 | public void setmWeekSize(int mWeekSize) {
126 | this.mWeekSize = mWeekSize;
127 | }
128 |
129 |
130 | /**
131 | * 设置星期的形式
132 | * @param weekString
133 | * 默认值 "日","一","二","三","四","五","六"
134 | */
135 | public void setWeekString(String[] weekString) {
136 | this.weekString = weekString;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/com/dsw/datepicker/WorkOrRelax.java:
--------------------------------------------------------------------------------
1 | package com.dsw.datepicker;
2 |
3 | public class WorkOrRelax {
4 | public int year;
5 | public int month;
6 | /**
7 | * 日期
8 | */
9 | public int day;
10 | /**
11 | * 状态:0位班,1位休息
12 | */
13 | public int state;
14 | public WorkOrRelax(int year, int month, int day, int state) {
15 | super();
16 | this.year = year;
17 | this.month = month;
18 | this.day = day;
19 | this.state = state;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------