├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── .travis.yml
├── LICENSE.txt
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── tubb
│ │ └── calendarselector
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── tubb
│ │ └── calendarselector
│ │ ├── MainActivity.java
│ │ ├── TestApplication.java
│ │ ├── custom
│ │ ├── AnimCalendarSelectorActivity.java
│ │ ├── AnimDayViewActivity.java
│ │ ├── AnimDayViewInflater.java
│ │ ├── AppleCalendarActivity.java
│ │ ├── AppleCalendarDayViewInflater.java
│ │ ├── CustomDayViewActivity.java
│ │ ├── CustomDayViewInflater.java
│ │ ├── CustomMainActivity.java
│ │ ├── DecorDayViewActivity.java
│ │ └── DecorDayViewInflater.java
│ │ └── normal
│ │ ├── CalendarSelectorActivity.java
│ │ ├── NormalActivity.java
│ │ ├── NormalMainActivity.java
│ │ ├── Protocol.java
│ │ ├── SingleMonthSelectorActivity.java
│ │ ├── StateSavedActivity.java
│ │ └── ViewPagerActivity.java
│ └── res
│ ├── drawable
│ ├── drawable_custom_dayview_text_bg.xml
│ ├── shape_custom_dayview_text_bg_normal.xml
│ └── shape_custom_dayview_text_bg_selected.xml
│ ├── layout
│ ├── activity_apple_calendar.xml
│ ├── activity_custom_decor.xml
│ ├── activity_custom_main.xml
│ ├── activity_main.xml
│ ├── activity_normal.xml
│ ├── activity_normal_main.xml
│ ├── activity_scrolling.xml
│ ├── activity_single_month_selector.xml
│ ├── activity_vp.xml
│ ├── item_apple_calendar.xml
│ ├── item_calendar.xml
│ ├── item_vp.xml
│ ├── layout_dayview_custom.xml
│ ├── layout_dayview_decor_custom.xml
│ ├── layout_monday_start.xml
│ ├── layout_saturday_start.xml
│ ├── layout_sunday_start.xml
│ ├── view_horizontal_decor.xml
│ └── view_vertical_decor.xml
│ ├── menu
│ ├── menu_mode.xml
│ └── menu_normal.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-zh
│ └── strings.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── art
├── 1.png
└── preview.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── tubb
│ │ └── calendarselector
│ │ ├── custom
│ │ ├── DayViewHolder.java
│ │ └── DayViewInflater.java
│ │ └── library
│ │ ├── CalendarSelector.java
│ │ ├── DefaultDayViewHolder.java
│ │ ├── DefaultDayViewInflater.java
│ │ ├── FullDay.java
│ │ ├── IntervalSelectListener.java
│ │ ├── MonthView.java
│ │ ├── SCDateUtils.java
│ │ ├── SCMonth.java
│ │ ├── SegmentSelectListener.java
│ │ └── SingleMonthSelector.java
│ └── res
│ ├── color
│ └── color_dayview_text_selector.xml
│ ├── drawable
│ ├── drawable_dayview_text_bg.xml
│ ├── shape_dayview_text_bg_normal.xml
│ └── shape_dayview_text_bg_selected.xml
│ ├── layout
│ └── layout_dayview_default.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | /projectFilesBackup
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
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 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | android:
3 | components:
4 | - tools
5 | - platform-tools
6 | - build-tools-23.0.2
7 | - android-23
8 | - extra-android-m2repository
9 | - sys-img-armeabi-v7a-android-18
10 |
11 | script:
12 | - ./gradlew build connectedCheck
13 |
14 | before_script:
15 | # Create and start an emulator for instrumentation tests.
16 | - echo no | android create avd --force -n test -t android-18 --abi armeabi-v7a
17 | - emulator -avd test -no-audio -no-window &
18 | - android-wait-for-emulator
19 | - adb shell input keyevent 82
20 |
21 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Calendar Selector
2 | =================
3 |
4 | [中文文档][9]
5 |
6 | A `calendar selector` for select dates, support select a `continuous` period of time and some `discontinuous` dates.
7 |
8 | Supported functionality:
9 |
10 | * select `continuous` or `discontinuous` dates
11 | * single month or multi months selection
12 | * intercept select event
13 | * save state
14 | * UI custom
15 | * indicate the start day of a week (`SUNDAY`、`SATURDAY`、`MONDAY`)
16 | * editor mode support, a good feeling of develop
17 | * API 8+
18 |
19 | Preview
20 | =======
21 |
22 | 
23 |
24 | Usage
25 | -----
26 |
27 | Add to dependencies
28 |
29 | ```groovy
30 | compile 'com.tubb.calendarselector.library:calendar-selector:0.2.3'
31 | ```
32 |
33 | Just use [MonthView][1], [MonthView][1] is a custom view for display month's days
34 |
35 | ```xml
36 |
43 | ```
44 |
45 | 
46 |
47 | We provide two `calendar selector` to select dates, one ( [SingleMonthSelector][2] ) is used for single month,
48 | another ( [CalendarSelector][3] ) is used for multi months, and the two `calendar selector` support `save state`, [StateSavedActivity][6] shows how to use them
49 |
50 | [SingleMonthSelector][2] usage
51 |
52 | ```java
53 | singleMonthSelector.bind(monthView);
54 | ```
55 |
56 | [CalendarSelector][3] usage ( support all `ViewGroup`'s subclasses, but except `ListView` )
57 |
58 | ```java
59 | calendarSelector.bind(containerViewGroup, monthView, itemPosition);
60 | ```
61 |
62 | We support intercept select event, so you can do something you like, such as define the limit select dates
63 |
64 | We include two select mode, one is for `continuous` dates (`SEGMENT` MODE), another is for `discontinuous` dates (`INTERVAL` MODE)
65 |
66 | SEGMENT mode
67 |
68 | ```java
69 | selector = new CalendarSelector(data, CalendarSelector.Mode.SEGMENT);
70 | selector.setSegmentSelectListener(new SegmentSelectListener() {
71 | @Override
72 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
73 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
74 | }
75 |
76 | @Override
77 | public boolean onInterceptSelect(FullDay selectingDay) { // one day intercept
78 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
79 | Toast.makeText(CalendarSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
80 | return true;
81 | }
82 | return super.onInterceptSelect(selectingDay);
83 | }
84 |
85 | @Override
86 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { // segment days intercept
87 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
88 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
89 | Log.d(TAG, "differDays " + differDays);
90 | if(differDays > 10) {
91 | Toast.makeText(CalendarSelectorActivity.this, "Selected days can't more than 10", Toast.LENGTH_SHORT).show();
92 | return true;
93 | }
94 | return super.onInterceptSelect(startDay, endDay);
95 | }
96 |
97 | @Override
98 | public void selectedSameDay(FullDay sameDay) { // selected the same day
99 | super.selectedSameDay(sameDay);
100 | }
101 | });
102 | ```
103 |
104 | INTERVAL mode
105 |
106 | ```java
107 | selector = new SingleMonthSelector(CalendarSelector.Mode.INTERVAL);
108 | selector.setIntervalSelectListener(new IntervalSelectListener() {
109 | @Override
110 | public void onIntervalSelect(List selectedDays) {
111 | Log.d(TAG, "interval selected days " + selectedDays.toString());
112 | }
113 |
114 | @Override
115 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
116 | if(selectedDays.size() >= 5) {
117 | Toast.makeText(SingleMonthSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show();
118 | return true;
119 | }
120 | return super.onInterceptSelect(selectedDays, selectingDay);
121 | }
122 | });
123 | ```
124 |
125 | More details please see [SingleMonthSelectorActivity][4] and [CalendarSelectorActivity][5]
126 |
127 | Custom
128 | ======
129 |
130 | `CalendarSelector` easy to custom, we abstract out the month's day ui to custom,
131 | so you can control the ui of month's day, just like a view, layout in xml
132 |
133 | ```xml
134 |
135 |
139 |
140 |
151 |
152 |
153 | ```
154 |
155 | then implement your `DayViewInflater`, used by MonthView (`MonthView.setSCMonth(scMonth, new CustomDayViewInflater(context))`)
156 |
157 | ```java
158 | public class CustomDayViewInflater extends DayViewInflater{
159 |
160 | public CustomDayViewInflater(Context context) {
161 | super(context);
162 | }
163 |
164 | @Override
165 | public DayViewHolder inflateDayView(ViewGroup container) {
166 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_custom, container, false);
167 | return new CustomDayViewHolder(dayView);
168 | }
169 |
170 | public static class CustomDayViewHolder extends DayViewHolder{
171 |
172 | protected TextView tvDay;
173 | private int mPrevMonthDayTextColor;
174 | private int mNextMonthDayTextColor;
175 |
176 | public CustomDayViewHolder(View dayView) {
177 | super(dayView);
178 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay);
179 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
180 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
181 | }
182 |
183 | @Override
184 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
185 | tvDay.setText(String.valueOf(day.getDay()));
186 | tvDay.setSelected(isSelected);
187 | }
188 |
189 | @Override
190 | public void setPrevMonthDayText(FullDay day) {
191 | tvDay.setTextColor(mPrevMonthDayTextColor);
192 | tvDay.setText(String.valueOf(day.getDay()));
193 | }
194 |
195 | @Override
196 | public void setNextMonthDayText(FullDay day) {
197 | tvDay.setTextColor(mNextMonthDayTextColor);
198 | tvDay.setText(String.valueOf(day.getDay()));
199 | }
200 |
201 | }
202 | }
203 | ```
204 |
205 | When day has selected, the DayViewHolder.setCurrentMonthDayText(FullDay day, boolean isSelected) method will be excute,
206 | at this moment, you can do something interesting (add animator for day view), please see [AnimDayViewInflater][8]
207 |
208 | ```java
209 | @Override
210 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
211 | boolean oldSelected = tvDay.isSelected();
212 | tvDay.setText(String.valueOf(day.getDay()));
213 | tvDay.setSelected(isSelected);
214 | // view selected animation
215 | if(!oldSelected && isSelected){
216 | AnimatorSet animatorSet = new AnimatorSet();
217 | animatorSet.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.anim.bounce_interpolator));
218 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "scaleX", 0.5f, 1.0f))
219 | .with(ObjectAnimator.ofFloat(tvDay, "scaleY", 0.5f, 1.0f));
220 | animatorSet.setDuration(500)
221 | .start();
222 | }
223 | }
224 | ```
225 |
226 | We also provide the ability for decorate day view, please see [DecorDayViewInflater][7]
227 | ```java
228 | @Override
229 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow) {
230 | return new Decor(mLayoutInflater.inflate(R.layout.view_horizontal_decor, container, false), true);
231 | }
232 |
233 | @Override
234 | public Decor inflateVerticalDecor(ViewGroup container, int col, int totalCol) {
235 | return new Decor(mLayoutInflater.inflate(R.layout.view_vertical_decor, container, false), true);
236 | }
237 | ```
238 |
239 | We include several attrs for [MonthView][1]
240 |
241 | ```xml
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 | ```
261 |
262 | Note
263 | ====
264 |
265 | If you have any question, just commit some issues
266 |
267 |
268 | License
269 | -------
270 |
271 | Copyright 2016 TUBB
272 |
273 | Licensed under the Apache License, Version 2.0 (the "License");
274 | you may not use this file except in compliance with the License.
275 | You may obtain a copy of the License at
276 |
277 | http://www.apache.org/licenses/LICENSE-2.0
278 |
279 | Unless required by applicable law or agreed to in writing, software
280 | distributed under the License is distributed on an "AS IS" BASIS,
281 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
282 | See the License for the specific language governing permissions and
283 | limitations under the License.
284 |
285 |
286 |
287 | [1]: https://github.com/TUBB/CalendarSelector/blob/master/library/src/main/java/com/tubb/calendarselector/library/MonthView.java
288 | [2]: https://github.com/TUBB/CalendarSelector/blob/master/library/src/main/java/com/tubb/calendarselector/library/SingleMonthSelector.java
289 | [3]: https://github.com/TUBB/CalendarSelector/blob/master/library/src/main/java/com/tubb/calendarselector/library/CalendarSelector.java
290 | [4]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/normal/SingleMonthSelectorActivity.java
291 | [5]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/normal/CalendarSelectorActivity.java
292 | [6]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/normal/StateSavedActivity.java
293 | [7]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/custom/DecorDayViewInflater.java
294 | [8]: https://github.com/TUBB/CalendarSelector/blob/master/app/src/main/java/com/tubb/calendarselector/custom/AnimDayViewInflater.java
295 | [9]: http://tubb.github.io/2016/04/17/Android%E6%97%A5%E6%9C%9F%E6%98%BE%E7%A4%BA%E5%92%8C%E9%80%89%E6%8B%A9%E5%BA%93/
296 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.compileSdkVersion
5 | buildToolsVersion rootProject.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.tubb.calendarselector"
9 | minSdkVersion 11
10 | targetSdkVersion rootProject.targetSdkVersion
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | packagingOptions {
21 | exclude 'LICENSE.txt'
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | compile project(':library')
28 | compile 'com.android.support:appcompat-v7:'+rootProject.appcompatVersion
29 | compile 'com.android.support:recyclerview-v7:'+rootProject.appcompatVersion
30 | compile 'com.android.support:design:23.1.1'
31 | compile 'com.github.moduth:blockcanary-ui:1.2.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tubingbing/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tubb/calendarselector/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.tubb.calendarselector.custom.CustomMainActivity;
9 | import com.tubb.calendarselector.normal.CalendarSelectorActivity;
10 | import com.tubb.calendarselector.normal.NormalActivity;
11 | import com.tubb.calendarselector.normal.NormalMainActivity;
12 | import com.tubb.calendarselector.normal.SingleMonthSelectorActivity;
13 | import com.tubb.calendarselector.normal.StateSavedActivity;
14 | import com.tubb.calendarselector.normal.ViewPagerActivity;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 |
18 | private static final String TAG = "mv";
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 | }
25 |
26 | public void viewClick(View view){
27 | switch (view.getId()){
28 | case R.id.bt_default:
29 | startActivity(new Intent(this, NormalMainActivity.class));
30 | break;
31 | case R.id.bt_custom:
32 | startActivity(new Intent(this, CustomMainActivity.class));
33 | break;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/TestApplication.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector;
2 |
3 | import android.app.Application;
4 |
5 | import com.github.moduth.blockcanary.BlockCanary;
6 | import com.github.moduth.blockcanary.BlockCanaryContext;
7 |
8 | /**
9 | * Created by tubingbing on 16/4/15.
10 | */
11 | public class TestApplication extends Application{
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 | // Do it on main process
17 | BlockCanary.install(this, new AppBlockCanaryContext()).start();
18 | }
19 |
20 | class AppBlockCanaryContext extends BlockCanaryContext {
21 | // override to provide context like app qualifier, uid, network type, block threshold, log save path
22 |
23 | // this is default block threshold, you can set it by phone's performance
24 | @Override
25 | public int getConfigBlockThreshold() {
26 | return 500;
27 | }
28 |
29 | // if set true, notification will be shown, else only write log file
30 | @Override
31 | public boolean isNeedDisplay() {
32 | return BuildConfig.DEBUG;
33 | }
34 |
35 | // path to save log file
36 | @Override
37 | public String getLogPath() {
38 | return "/blockcanary/performance";
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/AnimCalendarSelectorActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.support.v7.widget.SimpleItemAnimator;
8 | import android.util.Log;
9 | import android.util.SparseArray;
10 | import android.view.LayoutInflater;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import com.tubb.calendarselector.R;
19 | import com.tubb.calendarselector.library.CalendarSelector;
20 | import com.tubb.calendarselector.library.FullDay;
21 | import com.tubb.calendarselector.library.IntervalSelectListener;
22 | import com.tubb.calendarselector.library.MonthView;
23 | import com.tubb.calendarselector.library.SCDateUtils;
24 | import com.tubb.calendarselector.library.SCMonth;
25 | import com.tubb.calendarselector.library.SegmentSelectListener;
26 |
27 | import java.util.List;
28 |
29 | public class AnimCalendarSelectorActivity extends AppCompatActivity {
30 |
31 | private static final String TAG = "mv";
32 |
33 | CalendarSelector selector;
34 | RecyclerView rvCalendar;
35 | List data;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_scrolling);
41 | if(savedInstanceState != null)
42 | selector = savedInstanceState.getParcelable("selector");
43 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar);
44 | rvCalendar.setLayoutManager(new LinearLayoutManager(this));
45 | ((SimpleItemAnimator) rvCalendar.getItemAnimator()).setSupportsChangeAnimations(false);
46 | data = getData();
47 | segmentMode();
48 | }
49 |
50 | /**
51 | * segment mode
52 | */
53 | private void segmentMode(){
54 |
55 | data = getData();
56 |
57 | selector = new CalendarSelector(data, CalendarSelector.SEGMENT);
58 | selector.setSegmentSelectListener(new SegmentSelectListener() {
59 | @Override
60 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
61 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
62 | }
63 |
64 | @Override
65 | public boolean onInterceptSelect(FullDay selectingDay) { // one day intercept
66 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
67 | Toast.makeText(AnimCalendarSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
68 | return true;
69 | }
70 | return super.onInterceptSelect(selectingDay);
71 | }
72 |
73 | @Override
74 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { // segment days intercept
75 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
76 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
77 | Log.d(TAG, "differDays " + differDays);
78 | if(differDays > 10) {
79 | Toast.makeText(AnimCalendarSelectorActivity.this, "Selected days can't more than 10", Toast.LENGTH_SHORT).show();
80 | return true;
81 | }
82 | return super.onInterceptSelect(startDay, endDay);
83 | }
84 |
85 | @Override
86 | public void selectedSameDay(FullDay sameDay) { // selected the same day
87 | super.selectedSameDay(sameDay);
88 | }
89 | });
90 | rvCalendar.setAdapter(new CalendarAdpater(data));
91 | }
92 |
93 | /**
94 | * interval mode
95 | */
96 | private void intervalMode(){
97 | data = getData();
98 | selector = new CalendarSelector(data, CalendarSelector.INTERVAL);
99 | selector.setIntervalSelectListener(new IntervalSelectListener() {
100 | @Override
101 | public void onIntervalSelect(List selectedDays) {
102 | Log.d(TAG, "interval selected days " + selectedDays.toString());
103 | }
104 |
105 | @Override
106 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
107 | if(selectedDays.size() >= 5) {
108 | Toast.makeText(AnimCalendarSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show();
109 | return true;
110 | }
111 | return super.onInterceptSelect(selectedDays, selectingDay);
112 | }
113 | });
114 | rvCalendar.setAdapter(new CalendarAdpater(data));
115 | }
116 |
117 | public List getData() {
118 | return SCDateUtils.generateMonths(2016, 2018, SCMonth.SUNDAY_OF_WEEK);
119 | }
120 |
121 | class CalendarAdpater extends RecyclerView.Adapter{
122 |
123 | List months;
124 | DayViewInflater animDayViewInflater;
125 |
126 | public CalendarAdpater(List months){
127 | this.months = months;
128 | animDayViewInflater = new AnimDayViewInflater(AnimCalendarSelectorActivity.this);
129 | }
130 |
131 | @Override
132 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
133 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar, parent, false));
134 | }
135 |
136 | @Override
137 | public void onBindViewHolder(CalendarViewHolder holder, int position) {
138 | SCMonth scMonth = months.get(position);
139 | holder.tvMonthTitle.setText(String.format("%d-%d", scMonth.getYear(), scMonth.getMonth()));
140 | holder.monthView.setSCMonth(scMonth, animDayViewInflater);
141 | selector.bind(rvCalendar, holder.monthView, position);
142 | }
143 |
144 | @Override
145 | public int getItemCount() {
146 | return months.size();
147 | }
148 | }
149 |
150 | class CalendarViewHolder extends RecyclerView.ViewHolder{
151 |
152 | TextView tvMonthTitle;
153 | MonthView monthView;
154 |
155 | public CalendarViewHolder(View itemView) {
156 | super(itemView);
157 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle);
158 | monthView = (MonthView) itemView.findViewById(R.id.ssMv);
159 | }
160 | }
161 |
162 | @Override
163 | public boolean onCreateOptionsMenu(Menu menu) {
164 | getMenuInflater().inflate(R.menu.menu_mode, menu);
165 | return true;
166 | }
167 |
168 | @Override
169 | public boolean onOptionsItemSelected(MenuItem item) {
170 | int id = item.getItemId();
171 |
172 | if (id == R.id.action_segment) {
173 | segmentMode();
174 | return true;
175 | }
176 | else if (id == R.id.action_interval) {
177 | intervalMode();
178 | return true;
179 | }
180 |
181 | return super.onOptionsItemSelected(item);
182 | }
183 |
184 | @Override
185 | protected void onSaveInstanceState(Bundle outState) {
186 | outState.putParcelable("selector", selector);
187 | super.onSaveInstanceState(outState);
188 | }
189 |
190 | }
191 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/AnimDayViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.widget.TextView;
9 | import android.widget.Toast;
10 |
11 | import com.tubb.calendarselector.R;
12 | import com.tubb.calendarselector.library.FullDay;
13 | import com.tubb.calendarselector.library.IntervalSelectListener;
14 | import com.tubb.calendarselector.library.MonthView;
15 | import com.tubb.calendarselector.library.SCDateUtils;
16 | import com.tubb.calendarselector.library.SCMonth;
17 | import com.tubb.calendarselector.library.SegmentSelectListener;
18 | import com.tubb.calendarselector.library.SingleMonthSelector;
19 |
20 | import java.util.List;
21 |
22 | public class AnimDayViewActivity extends AppCompatActivity {
23 |
24 | private static final String TAG = "mv";
25 | SCMonth scMonth;
26 | private SingleMonthSelector selector;
27 | private MonthView monthView;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_single_month_selector);
33 | monthView = (MonthView) findViewById(R.id.ssMv);
34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle);
35 | if(savedInstanceState != null){
36 | scMonth = savedInstanceState.getParcelable("month");
37 | }
38 | if(scMonth == null)
39 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK);
40 | tvMonthTitle.setText(scMonth.toString());
41 | segmentMode();
42 | }
43 |
44 | private void segmentMode(){
45 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK);
46 | monthView.setSCMonth(scMonth, new AnimDayViewInflater(this));
47 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT);
48 | selector.setSegmentSelectListener(new SegmentSelectListener() {
49 | @Override
50 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
51 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
52 | }
53 |
54 | @Override
55 | public boolean onInterceptSelect(FullDay selectingDay) {
56 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
57 | Toast.makeText(AnimDayViewActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
58 | return true;
59 | }
60 | return super.onInterceptSelect(selectingDay);
61 | }
62 |
63 | @Override
64 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) {
65 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
66 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
67 | Log.d(TAG, "differDays " + differDays);
68 | if(differDays > 5) {
69 | Toast.makeText(AnimDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show();
70 | return true;
71 | }
72 | return super.onInterceptSelect(startDay, endDay);
73 | }
74 |
75 | });
76 | selector.bind(monthView);
77 | }
78 |
79 | private void intervalMode(){
80 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK);
81 | monthView.setSCMonth(scMonth, new AnimDayViewInflater(this));
82 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL);
83 | selector.setIntervalSelectListener(new IntervalSelectListener() {
84 | @Override
85 | public void onIntervalSelect(List selectedDays) {
86 | Log.d(TAG, "interval selected days " + selectedDays.toString());
87 | }
88 |
89 | @Override
90 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
91 | if(selectedDays.size() >= 5) {
92 | Toast.makeText(AnimDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show();
93 | return true;
94 | }
95 | return super.onInterceptSelect(selectedDays, selectingDay);
96 | }
97 | });
98 | selector.bind(monthView);
99 | }
100 |
101 | @Override
102 | public boolean onCreateOptionsMenu(Menu menu) {
103 | getMenuInflater().inflate(R.menu.menu_mode, menu);
104 | return true;
105 | }
106 |
107 | @Override
108 | public boolean onOptionsItemSelected(MenuItem item) {
109 | int id = item.getItemId();
110 |
111 | if (id == R.id.action_segment) {
112 | segmentMode();
113 | return true;
114 | }
115 | else if (id == R.id.action_interval) {
116 | intervalMode();
117 | return true;
118 | }
119 |
120 | return super.onOptionsItemSelected(item);
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/AnimDayViewInflater.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.support.v4.content.ContextCompat;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.view.animation.AnimationSet;
12 | import android.view.animation.AnimationUtils;
13 | import android.view.animation.BounceInterpolator;
14 | import android.widget.TextView;
15 |
16 | import com.tubb.calendarselector.R;
17 | import com.tubb.calendarselector.library.FullDay;
18 |
19 | /**
20 | * Created by tubingbing on 16/4/14.
21 | */
22 | public class AnimDayViewInflater extends DayViewInflater{
23 |
24 | public AnimDayViewInflater(Context context) {
25 | super(context);
26 | }
27 |
28 | @Override
29 | public DayViewHolder inflateDayView(ViewGroup container) {
30 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_custom, container, false);
31 | return new CustomDayViewHolder(dayView);
32 | }
33 |
34 | public static class CustomDayViewHolder extends DayViewHolder{
35 |
36 | protected TextView tvDay;
37 | private int mPrevMonthDayTextColor;
38 | private int mNextMonthDayTextColor;
39 |
40 | public CustomDayViewHolder(View dayView) {
41 | super(dayView);
42 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay);
43 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
44 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_dddddd);
45 | }
46 |
47 | @Override
48 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
49 | boolean oldSelected = tvDay.isSelected();
50 | tvDay.setText(String.valueOf(day.getDay()));
51 | tvDay.setSelected(isSelected);
52 | // selected animation
53 | if(!oldSelected && isSelected){
54 | AnimatorSet animatorSet = new AnimatorSet();
55 | animatorSet.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.anim.bounce_interpolator));
56 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "scaleX", 0.5f, 1.0f))
57 | .with(ObjectAnimator.ofFloat(tvDay, "scaleY", 0.5f, 1.0f));
58 | animatorSet.setDuration(500)
59 | .start();
60 | }
61 | }
62 |
63 | @Override
64 | public void setPrevMonthDayText(FullDay day) {
65 | tvDay.setTextColor(mPrevMonthDayTextColor);
66 | tvDay.setText(String.valueOf(day.getDay()));
67 | }
68 |
69 | @Override
70 | public void setNextMonthDayText(FullDay day) {
71 | tvDay.setTextColor(mNextMonthDayTextColor);
72 | tvDay.setText(String.valueOf(day.getDay()));
73 | }
74 |
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/AppleCalendarActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.LinearLayoutManager;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.support.v7.widget.SimpleItemAnimator;
12 | import android.util.Log;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.animation.AccelerateDecelerateInterpolator;
17 | import android.view.animation.AccelerateInterpolator;
18 | import android.view.animation.AnimationSet;
19 | import android.widget.LinearLayout;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import com.tubb.calendarselector.R;
24 | import com.tubb.calendarselector.library.CalendarSelector;
25 | import com.tubb.calendarselector.library.FullDay;
26 | import com.tubb.calendarselector.library.MonthView;
27 | import com.tubb.calendarselector.library.SCDateUtils;
28 | import com.tubb.calendarselector.library.SCMonth;
29 | import com.tubb.calendarselector.library.SegmentSelectListener;
30 | import com.tubb.calendarselector.library.SingleMonthSelector;
31 |
32 | import java.util.HashSet;
33 | import java.util.List;
34 | import java.util.Locale;
35 | import java.util.Set;
36 |
37 | /**
38 | * Created by tubingbing on 16/4/25.
39 | */
40 | public class AppleCalendarActivity extends AppCompatActivity{
41 |
42 | private RecyclerView rvCalendar;
43 | private CalendarSelector selector;
44 |
45 | @Override
46 | protected void onCreate(@Nullable Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_apple_calendar);
49 | setTitle("2016");
50 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar);
51 | rvCalendar.setLayoutManager(new LinearLayoutManager(this));
52 | ((SimpleItemAnimator) rvCalendar.getItemAnimator()).setSupportsChangeAnimations(false);
53 | List months = SCDateUtils.generateMonths(2016, 2016);
54 | rvCalendar.setAdapter(new CalendarAdpater(months));
55 | selector = new CalendarSelector(months, SingleMonthSelector.SEGMENT);
56 | selector.setSegmentSelectListener(new SegmentSelectListener() {
57 | @Override
58 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
59 | // TODO
60 | }
61 | });
62 | }
63 |
64 | class CalendarAdpater extends RecyclerView.Adapter{
65 |
66 | List months;
67 | DayViewInflater appleCalendarDayViewInflater;
68 | Set animPositionSet = new HashSet<>();
69 |
70 | public CalendarAdpater(List months){
71 | this.months = months;
72 | appleCalendarDayViewInflater = new AppleCalendarDayViewInflater(AppleCalendarActivity.this);
73 | }
74 |
75 | @Override
76 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
77 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_apple_calendar, parent, false));
78 | }
79 |
80 | public void onBindViewHolder(final CalendarViewHolder holder, final int position) {
81 | final SCMonth scMonth = months.get(position);
82 | holder.tvMonthTitle.setText(String.format(Locale.getDefault(), "%d月", scMonth.getMonth()));
83 | holder.monthView.setSCMonth(scMonth, appleCalendarDayViewInflater);
84 |
85 | // wait for MonthView measure finish
86 | holder.monthView.post(new Runnable() {
87 | @Override
88 | public void run() {
89 |
90 | final int firstdayOfWeekPosInMonth = scMonth.getFirstdayOfWeekPosInMonth();
91 | final int lineScrollX = -(firstdayOfWeekPosInMonth - 1) * holder.monthView.getDayWidth();
92 | final int monthScrollX = -(firstdayOfWeekPosInMonth - 1) * holder.monthView.getDayWidth()
93 | - (holder.monthView.getDayWidth() / 2 - holder.tvMonthTitle.getWidth() / 2);
94 |
95 | // avoid anim every time
96 | if(!animPositionSet.contains(position)){
97 | animPositionSet.add(position);
98 | ValueAnimator lineAnimator = ValueAnimator.ofInt(0, lineScrollX);
99 | lineAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
100 | @Override
101 | public void onAnimationUpdate(ValueAnimator animation) {
102 | int scrollX = (int) animation.getAnimatedValue();
103 | holder.flScrollLine.scrollTo(scrollX , 0);
104 | }
105 | });
106 |
107 | ValueAnimator monthAnimator = ValueAnimator.ofInt(0, monthScrollX);
108 | monthAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
109 | @Override
110 | public void onAnimationUpdate(ValueAnimator animation) {
111 | int scrollX = (int) animation.getAnimatedValue();
112 | holder.flScrollMonth.scrollTo(scrollX , 0);
113 | }
114 | });
115 | AnimatorSet animationSet = new AnimatorSet();
116 | animationSet.play(monthAnimator).with(lineAnimator);
117 | animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
118 | animationSet.setDuration(500);
119 | animationSet.start();
120 | }else{
121 | holder.flScrollLine.scrollTo(lineScrollX , 0);
122 | holder.flScrollMonth.scrollTo(monthScrollX , 0);
123 | }
124 |
125 | int dayCount = holder.monthView.getCurrentMonthLastRowDayCount();
126 | View decorView = holder.monthView.getLastHorizontalDecor();
127 | if(decorView != null)
128 | decorView.scrollTo((7 - dayCount)*holder.monthView.getDayWidth(), 0);
129 | }
130 | });
131 |
132 | selector.bind(rvCalendar, holder.monthView, position);
133 | }
134 |
135 | @Override
136 | public int getItemCount() {
137 | return months.size();
138 | }
139 | }
140 |
141 | class CalendarViewHolder extends RecyclerView.ViewHolder{
142 |
143 | View flScrollMonth;
144 | View flScrollLine;
145 | TextView tvMonthTitle;
146 | MonthView monthView;
147 |
148 | public CalendarViewHolder(View itemView) {
149 | super(itemView);
150 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle);
151 | monthView = (MonthView) itemView.findViewById(R.id.ssMv);
152 | flScrollMonth = itemView.findViewById(R.id.flScrollMonth);
153 | flScrollLine = itemView.findViewById(R.id.flScrollLine);
154 | }
155 | }
156 |
157 | }
158 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/AppleCalendarDayViewInflater.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.support.v4.content.ContextCompat;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.tubb.calendarselector.R;
12 | import com.tubb.calendarselector.library.FullDay;
13 |
14 | /**
15 | * Created by tubingbing on 16/4/14.
16 | */
17 | public class AppleCalendarDayViewInflater extends DayViewInflater{
18 |
19 | public AppleCalendarDayViewInflater(Context context) {
20 | super(context);
21 | }
22 |
23 | @Override
24 | public DayViewHolder inflateDayView(ViewGroup container) {
25 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_default, container, false);
26 | return new CustomDayViewHolder(dayView);
27 | }
28 |
29 | @Override
30 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow) {
31 | return new Decor(mLayoutInflater.inflate(R.layout.view_horizontal_decor, container, false));
32 | }
33 |
34 | @Override
35 | public boolean isShowHorizontalDecor(int row, int realRowCount) {
36 | if(row == 0 || row == realRowCount) return false;
37 | return super.isShowHorizontalDecor(row, realRowCount);
38 | }
39 |
40 | public static class CustomDayViewHolder extends DayViewHolder{
41 |
42 | protected TextView tvDay;
43 | private int mPrevMonthDayTextColor;
44 | private int mNextMonthDayTextColor;
45 |
46 | public CustomDayViewHolder(View dayView) {
47 | super(dayView);
48 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay);
49 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
50 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_dddddd);
51 | }
52 |
53 | @Override
54 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
55 | if(day.getWeekOf() == FullDay.WEEK_1 || day.getWeekOf() == FullDay.WEEK_7)
56 | tvDay.setTextColor(mPrevMonthDayTextColor);
57 | boolean oldSelected = tvDay.isSelected();
58 | tvDay.setText(String.valueOf(day.getDay()));
59 | tvDay.setSelected(isSelected);
60 | if(!oldSelected && isSelected){
61 | AnimatorSet animatorSet = new AnimatorSet();
62 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "rotationX", 0.0f, 360f))
63 | .with(ObjectAnimator.ofFloat(tvDay, "rotationY", 0.0f, 360f));
64 | animatorSet.setDuration(500)
65 | .start();
66 | }
67 | }
68 |
69 | @Override
70 | public void setPrevMonthDayText(FullDay day) {
71 | tvDay.setTextColor(mPrevMonthDayTextColor);
72 | tvDay.setText(String.valueOf(day.getDay()));
73 | }
74 |
75 | @Override
76 | public void setNextMonthDayText(FullDay day) {
77 | tvDay.setTextColor(mNextMonthDayTextColor);
78 | tvDay.setText(String.valueOf(day.getDay()));
79 | }
80 |
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/CustomDayViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.widget.TextView;
9 | import android.widget.Toast;
10 |
11 | import com.tubb.calendarselector.R;
12 | import com.tubb.calendarselector.library.FullDay;
13 | import com.tubb.calendarselector.library.IntervalSelectListener;
14 | import com.tubb.calendarselector.library.MonthView;
15 | import com.tubb.calendarselector.library.SCDateUtils;
16 | import com.tubb.calendarselector.library.SCMonth;
17 | import com.tubb.calendarselector.library.SegmentSelectListener;
18 | import com.tubb.calendarselector.library.SingleMonthSelector;
19 |
20 | import java.util.List;
21 |
22 | public class CustomDayViewActivity extends AppCompatActivity {
23 |
24 | private static final String TAG = "mv";
25 | SCMonth scMonth;
26 | private SingleMonthSelector selector;
27 | private MonthView monthView;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_single_month_selector);
33 | monthView = (MonthView) findViewById(R.id.ssMv);
34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle);
35 | if(savedInstanceState != null){
36 | scMonth = savedInstanceState.getParcelable("month");
37 | }
38 | if(scMonth == null)
39 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
40 | tvMonthTitle.setText(scMonth.toString());
41 | segmentMode();
42 | }
43 |
44 | private void segmentMode(){
45 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT);
46 | monthView.setSCMonth(scMonth, new CustomDayViewInflater(this));
47 | selector.setSegmentSelectListener(new SegmentSelectListener() {
48 | @Override
49 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
50 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
51 | }
52 |
53 | @Override
54 | public boolean onInterceptSelect(FullDay selectingDay) {
55 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
56 | Toast.makeText(CustomDayViewActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
57 | return true;
58 | }
59 | return super.onInterceptSelect(selectingDay);
60 | }
61 |
62 | @Override
63 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) {
64 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
65 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
66 | Log.d(TAG, "differDays " + differDays);
67 | if(differDays > 5) {
68 | Toast.makeText(CustomDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show();
69 | return true;
70 | }
71 | return super.onInterceptSelect(startDay, endDay);
72 | }
73 |
74 | });
75 | selector.bind(monthView);
76 | }
77 |
78 | private void intervalMode(){
79 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
80 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL);
81 | monthView.setSCMonth(scMonth, new CustomDayViewInflater(this));
82 | selector.setIntervalSelectListener(new IntervalSelectListener() {
83 | @Override
84 | public void onIntervalSelect(List selectedDays) {
85 | Log.d(TAG, "interval selected days " + selectedDays.toString());
86 | }
87 |
88 | @Override
89 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
90 | if(selectedDays.size() >= 5) {
91 | Toast.makeText(CustomDayViewActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show();
92 | return true;
93 | }
94 | return super.onInterceptSelect(selectedDays, selectingDay);
95 | }
96 | });
97 | selector.bind(monthView);
98 | }
99 |
100 | @Override
101 | public boolean onCreateOptionsMenu(Menu menu) {
102 | getMenuInflater().inflate(R.menu.menu_mode, menu);
103 | return true;
104 | }
105 |
106 | @Override
107 | public boolean onOptionsItemSelected(MenuItem item) {
108 | int id = item.getItemId();
109 |
110 | if (id == R.id.action_segment) {
111 | segmentMode();
112 | return true;
113 | }
114 | else if (id == R.id.action_interval) {
115 | intervalMode();
116 | return true;
117 | }
118 |
119 | return super.onOptionsItemSelected(item);
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/CustomDayViewInflater.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.content.Context;
4 | import android.support.v4.content.ContextCompat;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.tubb.calendarselector.R;
10 | import com.tubb.calendarselector.library.FullDay;
11 |
12 | /**
13 | * Created by tubingbing on 16/4/14.
14 | */
15 | public class CustomDayViewInflater extends DayViewInflater{
16 |
17 | public CustomDayViewInflater(Context context) {
18 | super(context);
19 | }
20 |
21 | @Override
22 | public DayViewHolder inflateDayView(ViewGroup container) {
23 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_custom, container, false);
24 | return new CustomDayViewHolder(dayView);
25 | }
26 |
27 | public static class CustomDayViewHolder extends DayViewHolder{
28 |
29 | protected TextView tvDay;
30 | private int mPrevMonthDayTextColor;
31 | private int mNextMonthDayTextColor;
32 |
33 | public CustomDayViewHolder(View dayView) {
34 | super(dayView);
35 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay);
36 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
37 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
38 | }
39 |
40 | @Override
41 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
42 | tvDay.setText(String.valueOf(day.getDay()));
43 | tvDay.setSelected(isSelected);
44 | }
45 |
46 | @Override
47 | public void setPrevMonthDayText(FullDay day) {
48 | tvDay.setTextColor(mPrevMonthDayTextColor);
49 | tvDay.setText(String.valueOf(day.getDay()));
50 | }
51 |
52 | @Override
53 | public void setNextMonthDayText(FullDay day) {
54 | tvDay.setTextColor(mNextMonthDayTextColor);
55 | tvDay.setText(String.valueOf(day.getDay()));
56 | }
57 |
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/CustomMainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.tubb.calendarselector.R;
9 | import com.tubb.calendarselector.normal.CalendarSelectorActivity;
10 | import com.tubb.calendarselector.normal.NormalActivity;
11 | import com.tubb.calendarselector.normal.SingleMonthSelectorActivity;
12 | import com.tubb.calendarselector.normal.StateSavedActivity;
13 | import com.tubb.calendarselector.normal.ViewPagerActivity;
14 |
15 | public class CustomMainActivity extends AppCompatActivity {
16 |
17 | private static final String TAG = "mv";
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_custom_main);
23 | }
24 |
25 | public void viewClick(View view){
26 | switch (view.getId()){
27 | case R.id.bt_normal:
28 | startActivity(new Intent(this, CustomDayViewActivity.class));
29 | break;
30 | case R.id.bt_anim:
31 | startActivity(new Intent(this, AnimDayViewActivity.class));
32 | break;
33 | case R.id.bt_anim_calendar:
34 | startActivity(new Intent(this, AnimCalendarSelectorActivity.class));
35 | break;
36 | case R.id.bt_decor:
37 | startActivity(new Intent(this, DecorDayViewActivity.class));
38 | break;
39 | case R.id.bt_apple_calendar:
40 | startActivity(new Intent(this, AppleCalendarActivity.class));
41 | break;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/DecorDayViewActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.widget.TextView;
9 | import android.widget.Toast;
10 |
11 | import com.tubb.calendarselector.R;
12 | import com.tubb.calendarselector.library.FullDay;
13 | import com.tubb.calendarselector.library.IntervalSelectListener;
14 | import com.tubb.calendarselector.library.MonthView;
15 | import com.tubb.calendarselector.library.SCDateUtils;
16 | import com.tubb.calendarselector.library.SCMonth;
17 | import com.tubb.calendarselector.library.SegmentSelectListener;
18 | import com.tubb.calendarselector.library.SingleMonthSelector;
19 |
20 | import java.util.List;
21 |
22 | public class DecorDayViewActivity extends AppCompatActivity {
23 |
24 | private static final String TAG = "mv";
25 | SCMonth scMonth;
26 | private SingleMonthSelector selector;
27 | private MonthView monthView;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_custom_decor);
33 | monthView = (MonthView) findViewById(R.id.ssMv);
34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle);
35 | if(savedInstanceState != null){
36 | scMonth = savedInstanceState.getParcelable("month");
37 | }
38 | if(scMonth == null)
39 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
40 | tvMonthTitle.setText(scMonth.toString());
41 | segmentMode();
42 | }
43 |
44 | private void segmentMode(){
45 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT);
46 | monthView.setSCMonth(scMonth, new DecorDayViewInflater(this));
47 | selector.setSegmentSelectListener(new SegmentSelectListener() {
48 | @Override
49 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
50 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
51 | }
52 |
53 | @Override
54 | public boolean onInterceptSelect(FullDay selectingDay) {
55 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
56 | Toast.makeText(DecorDayViewActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
57 | return true;
58 | }
59 | return super.onInterceptSelect(selectingDay);
60 | }
61 |
62 | @Override
63 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) {
64 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
65 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
66 | Log.d(TAG, "differDays " + differDays);
67 | if(differDays > 15) {
68 | Toast.makeText(DecorDayViewActivity.this, "Selected days can't more than 15", Toast.LENGTH_SHORT).show();
69 | return true;
70 | }
71 | return super.onInterceptSelect(startDay, endDay);
72 | }
73 |
74 | });
75 | selector.bind(monthView);
76 | }
77 |
78 | private void intervalMode(){
79 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
80 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL);
81 | monthView.setSCMonth(scMonth, new DecorDayViewInflater(this));
82 | selector.setIntervalSelectListener(new IntervalSelectListener() {
83 | @Override
84 | public void onIntervalSelect(List selectedDays) {
85 | Log.d(TAG, "interval selected days " + selectedDays.toString());
86 | }
87 |
88 | @Override
89 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
90 | if(selectedDays.size() >= 15) {
91 | Toast.makeText(DecorDayViewActivity.this, "Selected days can't more than 15", Toast.LENGTH_LONG).show();
92 | return true;
93 | }
94 | return super.onInterceptSelect(selectedDays, selectingDay);
95 | }
96 | });
97 | selector.bind(monthView);
98 | }
99 |
100 | @Override
101 | public boolean onCreateOptionsMenu(Menu menu) {
102 | getMenuInflater().inflate(R.menu.menu_mode, menu);
103 | return true;
104 | }
105 |
106 | @Override
107 | public boolean onOptionsItemSelected(MenuItem item) {
108 | int id = item.getItemId();
109 |
110 | if (id == R.id.action_segment) {
111 | segmentMode();
112 | return true;
113 | }
114 | else if (id == R.id.action_interval) {
115 | intervalMode();
116 | return true;
117 | }
118 |
119 | return super.onOptionsItemSelected(item);
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/custom/DecorDayViewInflater.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.graphics.Canvas;
7 | import android.graphics.Paint;
8 | import android.support.v4.content.ContextCompat;
9 | import android.support.v4.view.ViewCompat;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.view.animation.AnimationUtils;
13 | import android.widget.TextView;
14 |
15 | import com.tubb.calendarselector.R;
16 | import com.tubb.calendarselector.library.FullDay;
17 |
18 | /**
19 | * Created by tubingbing on 16/4/14.
20 | */
21 | public class DecorDayViewInflater extends DayViewInflater{
22 |
23 | public DecorDayViewInflater(Context context) {
24 | super(context);
25 | }
26 |
27 | @Override
28 | public DayViewHolder inflateDayView(ViewGroup container) {
29 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_decor_custom, container, false);
30 | return new CustomDayViewHolder(dayView);
31 | }
32 |
33 | @Override
34 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow) {
35 | return new Decor(mLayoutInflater.inflate(R.layout.view_horizontal_decor, container, false));
36 | }
37 |
38 | @Override
39 | public Decor inflateVerticalDecor(ViewGroup container, int col, int totalCol) {
40 | return new Decor(mLayoutInflater.inflate(R.layout.view_vertical_decor, container, false));
41 | }
42 |
43 | public static class CustomDayViewHolder extends DayViewHolder{
44 |
45 | protected TextView tvDay;
46 | private int mPrevMonthDayTextColor;
47 | private int mNextMonthDayTextColor;
48 |
49 | public CustomDayViewHolder(View dayView) {
50 | super(dayView);
51 | tvDay = (TextView) dayView.findViewById(com.tubb.calendarselector.library.R.id.tvDay);
52 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_999999);
53 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, com.tubb.calendarselector.library.R.color.c_dddddd);
54 | }
55 |
56 | @Override
57 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
58 | boolean oldSelected = tvDay.isSelected();
59 | tvDay.setText(String.valueOf(day.getDay()));
60 | tvDay.setSelected(isSelected);
61 | if(!oldSelected && isSelected){
62 | AnimatorSet animatorSet = new AnimatorSet();
63 | animatorSet.play(ObjectAnimator.ofFloat(tvDay, "rotationX", 0.0f, 360f))
64 | .with(ObjectAnimator.ofFloat(tvDay, "rotationY", 0.0f, 360f));
65 | animatorSet.setDuration(500)
66 | .start();
67 | }
68 | }
69 |
70 | @Override
71 | public void setPrevMonthDayText(FullDay day) {
72 | tvDay.setTextColor(mPrevMonthDayTextColor);
73 | tvDay.setText(String.valueOf(day.getDay()));
74 | }
75 |
76 | @Override
77 | public void setNextMonthDayText(FullDay day) {
78 | tvDay.setTextColor(mNextMonthDayTextColor);
79 | tvDay.setText(String.valueOf(day.getDay()));
80 | }
81 |
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/CalendarSelectorActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.SimpleItemAnimator;
9 | import android.util.Log;
10 | import android.view.LayoutInflater;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import com.tubb.calendarselector.R;
19 | import com.tubb.calendarselector.library.SCDateUtils;
20 | import com.tubb.calendarselector.library.FullDay;
21 | import com.tubb.calendarselector.library.IntervalSelectListener;
22 | import com.tubb.calendarselector.library.SCMonth;
23 | import com.tubb.calendarselector.library.CalendarSelector;
24 | import com.tubb.calendarselector.library.MonthView;
25 | import com.tubb.calendarselector.library.SegmentSelectListener;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | public class CalendarSelectorActivity extends AppCompatActivity {
31 |
32 | private static final String TAG = "mv";
33 |
34 | CalendarSelector selector;
35 | RecyclerView rvCalendar;
36 | List data;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_scrolling);
42 | if(savedInstanceState != null)
43 | selector = savedInstanceState.getParcelable("selector");
44 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar);
45 | rvCalendar.setLayoutManager(new LinearLayoutManager(this));
46 | ((SimpleItemAnimator) rvCalendar.getItemAnimator()).setSupportsChangeAnimations(false);
47 | data = getData();
48 | segmentMode();
49 | // intervalMode();
50 | }
51 |
52 | /**
53 | * segment mode
54 | */
55 | private void segmentMode(){
56 |
57 | data = getData();
58 |
59 | selector = new CalendarSelector(data, CalendarSelector.SEGMENT);
60 | selector.addSelectedSegment(new FullDay(2016, 3, 10), new FullDay(2016, 4, 1));
61 | selector.setSegmentSelectListener(new SegmentSelectListener() {
62 | @Override
63 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
64 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
65 | }
66 |
67 | @Override
68 | public boolean onInterceptSelect(FullDay selectingDay) { // one day intercept
69 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
70 | Toast.makeText(CalendarSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
71 | return true;
72 | }
73 | return super.onInterceptSelect(selectingDay);
74 | }
75 |
76 | @Override
77 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) { // segment days intercept
78 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
79 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
80 | Log.d(TAG, "differDays " + differDays);
81 | if(differDays > 10) {
82 | Toast.makeText(CalendarSelectorActivity.this, "Selected days can't more than 10", Toast.LENGTH_SHORT).show();
83 | return true;
84 | }
85 | return super.onInterceptSelect(startDay, endDay);
86 | }
87 |
88 | @Override
89 | public void selectedSameDay(FullDay sameDay) { // selected the same day
90 | super.selectedSameDay(sameDay);
91 | }
92 | });
93 | rvCalendar.setAdapter(new CalendarAdpater(data));
94 | }
95 |
96 | /**
97 | * interval mode
98 | */
99 | private void intervalMode(){
100 | data = getData();
101 | selector = new CalendarSelector(data, CalendarSelector.INTERVAL);
102 | selector.addSelectedInterval(new ArrayList(){
103 | {
104 | add(new FullDay(2016, 2, 4));
105 | add(new FullDay(2016, 3, 4));
106 | add(new FullDay(2016, 3, 5));
107 | add(new FullDay(2016, 4, 4));
108 | }
109 | });
110 | selector.setIntervalSelectListener(new IntervalSelectListener() {
111 | @Override
112 | public void onIntervalSelect(List selectedDays) {
113 | Log.d(TAG, "interval selected days " + selectedDays.toString());
114 | }
115 |
116 | @Override
117 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
118 | if(selectedDays.size() >= 5) {
119 | Toast.makeText(CalendarSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show();
120 | return true;
121 | }
122 | return super.onInterceptSelect(selectedDays, selectingDay);
123 | }
124 | });
125 | rvCalendar.setAdapter(new CalendarAdpater(data));
126 | }
127 |
128 | public List getData() {
129 | return SCDateUtils.generateMonths(2016, 2018, SCMonth.SUNDAY_OF_WEEK);
130 | }
131 |
132 | class CalendarAdpater extends RecyclerView.Adapter{
133 |
134 | List months;
135 |
136 | public CalendarAdpater(List months){
137 | this.months = months;
138 | }
139 |
140 | @Override
141 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
142 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar, parent, false));
143 | }
144 |
145 | @Override
146 | public void onBindViewHolder(CalendarViewHolder holder, int position) {
147 | SCMonth scMonth = months.get(position);
148 | holder.tvMonthTitle.setText(String.format("%d-%d", scMonth.getYear(), scMonth.getMonth()));
149 | holder.monthView.setSCMonth(scMonth);
150 | selector.bind(rvCalendar, holder.monthView, position);
151 | }
152 |
153 | @Override
154 | public int getItemCount() {
155 | return months.size();
156 | }
157 | }
158 |
159 | class CalendarViewHolder extends RecyclerView.ViewHolder{
160 |
161 | TextView tvMonthTitle;
162 | MonthView monthView;
163 |
164 | public CalendarViewHolder(View itemView) {
165 | super(itemView);
166 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle);
167 | monthView = (MonthView) itemView.findViewById(R.id.ssMv);
168 | }
169 | }
170 |
171 | @Override
172 | public boolean onCreateOptionsMenu(Menu menu) {
173 | getMenuInflater().inflate(R.menu.menu_mode, menu);
174 | return true;
175 | }
176 |
177 | @Override
178 | public boolean onOptionsItemSelected(MenuItem item) {
179 | int id = item.getItemId();
180 |
181 | if (id == R.id.action_segment) {
182 | segmentMode();
183 | return true;
184 | }
185 | else if (id == R.id.action_interval) {
186 | intervalMode();
187 | return true;
188 | }
189 |
190 | return super.onOptionsItemSelected(item);
191 | }
192 |
193 |
194 | @Override
195 | protected void onSaveInstanceState(Bundle outState) {
196 | outState.putParcelable("selector", selector);
197 | super.onSaveInstanceState(outState);
198 | }
199 |
200 | }
201 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/NormalActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.TextView;
6 |
7 | import com.tubb.calendarselector.R;
8 | import com.tubb.calendarselector.library.FullDay;
9 | import com.tubb.calendarselector.library.SCMonth;
10 | import com.tubb.calendarselector.library.MonthView;
11 |
12 | public class NormalActivity extends AppCompatActivity {
13 |
14 | private static final String TAG = "mv";
15 | SCMonth scMonth;
16 | private MonthView monthView;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_normal);
22 | monthView = (MonthView) findViewById(R.id.ssMv);
23 |
24 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle);
25 | if(savedInstanceState != null){
26 | scMonth = savedInstanceState.getParcelable("month");
27 | }
28 | if(scMonth == null)
29 | scMonth = new SCMonth(2016, 5, SCMonth.SUNDAY_OF_WEEK);
30 | tvMonthTitle.setText(scMonth.toString());
31 | monthView.setSCMonth(scMonth);
32 | monthView.setMonthDayClickListener(new MonthView.OnMonthDayClickListener() {
33 | @Override
34 | public void onMonthDayClick(FullDay day) {
35 | monthView.clearSelectedDays();
36 | monthView.addSelectedDay(day);
37 | }
38 | });
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/NormalMainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.tubb.calendarselector.R;
9 |
10 | public class NormalMainActivity extends AppCompatActivity {
11 |
12 | private static final String TAG = "mv";
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_normal_main);
18 | }
19 |
20 | public void viewClick(View view){
21 | switch (view.getId()){
22 | case R.id.bt_normal:
23 | startActivity(new Intent(this, NormalActivity.class));
24 | break;
25 | case R.id.bt_single:
26 | startActivity(new Intent(this, SingleMonthSelectorActivity.class));
27 | break;
28 | case R.id.bt_calendar:
29 | startActivity(new Intent(this, CalendarSelectorActivity.class));
30 | break;
31 | case R.id.bt_savedstate:
32 | startActivity(new Intent(this, StateSavedActivity.class));
33 | break;
34 | case R.id.bt_vp:
35 | startActivity(new Intent(this, ViewPagerActivity.class));
36 | break;
37 | case R.id.bt_state:
38 | startActivity(new Intent(this, StateSavedActivity.class));
39 | break;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/Protocol.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import com.tubb.calendarselector.library.SCMonth;
4 |
5 | /**
6 | * Created by tubingbing on 16/3/9.
7 | */
8 | public interface Protocol {
9 | void clickNextMonthDay(SCMonth currentMonth);
10 | void clickPrevMonthDay(SCMonth currentMonth);
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/SingleMonthSelectorActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.widget.TextView;
9 | import android.widget.Toast;
10 |
11 | import com.tubb.calendarselector.R;
12 | import com.tubb.calendarselector.library.MonthView;
13 | import com.tubb.calendarselector.library.SCDateUtils;
14 | import com.tubb.calendarselector.library.FullDay;
15 | import com.tubb.calendarselector.library.IntervalSelectListener;
16 | import com.tubb.calendarselector.library.SCMonth;
17 | import com.tubb.calendarselector.library.SegmentSelectListener;
18 | import com.tubb.calendarselector.library.SingleMonthSelector;
19 |
20 | import java.util.List;
21 |
22 | public class SingleMonthSelectorActivity extends AppCompatActivity {
23 |
24 | private static final String TAG = "mv";
25 | SCMonth scMonth;
26 | private SingleMonthSelector selector;
27 | private MonthView monthView;
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_single_month_selector);
33 | monthView = (MonthView) findViewById(R.id.ssMv);
34 | TextView tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle);
35 | if(savedInstanceState != null){
36 | scMonth = savedInstanceState.getParcelable("month");
37 | }
38 | if(scMonth == null)
39 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
40 | tvMonthTitle.setText(scMonth.toString());
41 | segmentMode();
42 | }
43 |
44 | private void segmentMode(){
45 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
46 |
47 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.SEGMENT);
48 | selector.addSelectedSegment(new FullDay(2016, 2, 4), new FullDay(2016, 2, 7));
49 | monthView.setSCMonth(scMonth);
50 | selector.setSegmentSelectListener(new SegmentSelectListener() {
51 | @Override
52 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
53 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
54 | }
55 |
56 | @Override
57 | public boolean onInterceptSelect(FullDay selectingDay) {
58 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
59 | Toast.makeText(SingleMonthSelectorActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
60 | return true;
61 | }
62 | return super.onInterceptSelect(selectingDay);
63 | }
64 |
65 | @Override
66 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) {
67 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
68 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
69 | Log.d(TAG, "differDays " + differDays);
70 | if(differDays > 5) {
71 | Toast.makeText(SingleMonthSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show();
72 | return true;
73 | }
74 | return super.onInterceptSelect(startDay, endDay);
75 | }
76 |
77 | });
78 | selector.bind(monthView);
79 | }
80 |
81 | private void intervalMode(){
82 | scMonth = new SCMonth(2016, 2, SCMonth.SUNDAY_OF_WEEK);
83 | selector = new SingleMonthSelector(scMonth, SingleMonthSelector.INTERVAL);
84 | selector.addSelectedInterval(new FullDay(2016, 2, 4));
85 | selector.addSelectedInterval(new FullDay(2016, 2, 5));
86 | selector.addSelectedInterval(new FullDay(2016, 2, 7));
87 | monthView.setSCMonth(scMonth);
88 | selector.setIntervalSelectListener(new IntervalSelectListener() {
89 | @Override
90 | public void onIntervalSelect(List selectedDays) {
91 | Log.d(TAG, "interval selected days " + selectedDays.toString());
92 | }
93 |
94 | @Override
95 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay) {
96 | if(selectedDays.size() >= 5) {
97 | Toast.makeText(SingleMonthSelectorActivity.this, "Selected days can't more than 5", Toast.LENGTH_LONG).show();
98 | return true;
99 | }
100 | return super.onInterceptSelect(selectedDays, selectingDay);
101 | }
102 | });
103 | selector.bind(monthView);
104 | }
105 |
106 | @Override
107 | public boolean onCreateOptionsMenu(Menu menu) {
108 | getMenuInflater().inflate(R.menu.menu_mode, menu);
109 | return true;
110 | }
111 |
112 | @Override
113 | public boolean onOptionsItemSelected(MenuItem item) {
114 | int id = item.getItemId();
115 |
116 | if (id == R.id.action_segment) {
117 | segmentMode();
118 | return true;
119 | }
120 | else if (id == R.id.action_interval) {
121 | intervalMode();
122 | return true;
123 | }
124 |
125 | return super.onOptionsItemSelected(item);
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/StateSavedActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.tubb.calendarselector.R;
15 | import com.tubb.calendarselector.library.CalendarSelector;
16 | import com.tubb.calendarselector.library.SCDateUtils;
17 | import com.tubb.calendarselector.library.FullDay;
18 | import com.tubb.calendarselector.library.SCMonth;
19 | import com.tubb.calendarselector.library.MonthView;
20 | import com.tubb.calendarselector.library.SegmentSelectListener;
21 |
22 | import java.util.List;
23 |
24 | public class StateSavedActivity extends AppCompatActivity {
25 |
26 | private static final String TAG = "mv";
27 |
28 | CalendarSelector processor;
29 | RecyclerView rvCalendar;
30 | List data;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_scrolling);
36 | if(savedInstanceState != null){
37 | processor = savedInstanceState.getParcelable("selector");
38 | }
39 | if(processor != null){ // restore data
40 | data = processor.getDataList();
41 | }else{ // generate data
42 | data = getData();
43 | processor = new CalendarSelector(data, CalendarSelector.SEGMENT);
44 | }
45 |
46 | rvCalendar = (RecyclerView) findViewById(R.id.rvCalendar);
47 | rvCalendar.setLayoutManager(new LinearLayoutManager(this));
48 |
49 | processor.setSegmentSelectListener(new SegmentSelectListener() {
50 | @Override
51 | public void onSegmentSelect(FullDay startDay, FullDay endDay) {
52 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
53 | }
54 |
55 | @Override
56 | public boolean onInterceptSelect(FullDay selectingDay) {
57 | if(SCDateUtils.isToday(selectingDay.getYear(), selectingDay.getMonth(), selectingDay.getDay())){
58 | Toast.makeText(StateSavedActivity.this, "Today can't be selected", Toast.LENGTH_SHORT).show();
59 | return true;
60 | }
61 | return super.onInterceptSelect(selectingDay);
62 | }
63 |
64 | @Override
65 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay) {
66 | int differDays = SCDateUtils.countDays(startDay.getYear(), startDay.getMonth(), startDay.getDay(),
67 | endDay.getYear(), endDay.getMonth(), endDay.getDay());
68 | Log.d(TAG, "segment select " + startDay.toString() + " : " + endDay.toString());
69 | Log.d(TAG, "differDays " + differDays);
70 | if(differDays > 5) {
71 | Toast.makeText(StateSavedActivity.this, "Selected days can't more than 5", Toast.LENGTH_SHORT).show();
72 | return true;
73 | }
74 | return super.onInterceptSelect(startDay, endDay);
75 | }
76 | });
77 | rvCalendar.setAdapter(new CalendarAdpater(data));
78 | }
79 |
80 | public List getData() {
81 | return SCDateUtils.generateMonths(2016, 2017, SCMonth.SUNDAY_OF_WEEK);
82 | }
83 |
84 | class CalendarAdpater extends RecyclerView.Adapter{
85 |
86 | List months;
87 |
88 | public CalendarAdpater(List months){
89 | this.months = months;
90 | }
91 |
92 | @Override
93 | public CalendarViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
94 | return new CalendarViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_calendar, parent, false));
95 | }
96 |
97 | @Override
98 | public void onBindViewHolder(CalendarViewHolder holder, int position) {
99 | SCMonth SCMonth = months.get(position);
100 | holder.tvMonthTitle.setText(String.format("%d-%d", SCMonth.getYear(), SCMonth.getMonth()));
101 | holder.monthView.setSCMonth(SCMonth);
102 | processor.bind(rvCalendar, holder.monthView, position);
103 | }
104 |
105 | @Override
106 | public int getItemCount() {
107 | return months.size();
108 | }
109 | }
110 |
111 | class CalendarViewHolder extends RecyclerView.ViewHolder{
112 |
113 | TextView tvMonthTitle;
114 | MonthView monthView;
115 |
116 | public CalendarViewHolder(View itemView) {
117 | super(itemView);
118 | tvMonthTitle = (TextView) itemView.findViewById(R.id.tvMonthTitle);
119 | monthView = (MonthView) itemView.findViewById(R.id.ssMv);
120 | }
121 | }
122 |
123 | @Override
124 | protected void onSaveInstanceState(Bundle outState) {
125 | outState.putParcelable("selector", processor);
126 | super.onSaveInstanceState(outState);
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tubb/calendarselector/normal/ViewPagerActivity.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.normal;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentManager;
8 | import android.support.v4.app.FragmentPagerAdapter;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v7.app.AppCompatActivity;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.tubb.calendarselector.R;
18 | import com.tubb.calendarselector.library.FullDay;
19 | import com.tubb.calendarselector.library.MonthView;
20 | import com.tubb.calendarselector.library.SCDateUtils;
21 | import com.tubb.calendarselector.library.SCMonth;
22 |
23 | import java.util.ArrayList;
24 | import java.util.List;
25 |
26 | public class ViewPagerActivity extends AppCompatActivity implements Protocol {
27 |
28 | private static final String TAG = "mv";
29 |
30 | TextView tvMonthTitle;
31 | ViewPager vpMonth;
32 | private List months;
33 |
34 | @Override
35 | protected void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_vp);
38 |
39 | tvMonthTitle = (TextView) findViewById(R.id.tvMonthTitle);
40 | vpMonth = (ViewPager) findViewById(R.id.vpMonth);
41 |
42 | months = SCDateUtils.generateMonths(2016, 3, 2016, 12, SCMonth.SUNDAY_OF_WEEK);
43 | tvMonthTitle.setText(months.get(0).toString());
44 |
45 | List fragments = new ArrayList<>(months.size());
46 | for (SCMonth month:months){
47 | fragments.add(MonthFragment.newInstance(month));
48 | }
49 | vpMonth.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
50 | @Override
51 | public void onPageSelected(int position) {
52 | SCMonth month = months.get(position);
53 | tvMonthTitle.setText(month.toString());
54 | }
55 | });
56 | vpMonth.setAdapter(new MonthFragmentAdapter(getSupportFragmentManager(), fragments));
57 | }
58 |
59 | @Override
60 | public void clickNextMonthDay(SCMonth currentMonth) {
61 | int currentIndex = months.indexOf(currentMonth);
62 | if(currentIndex+1 < months.size())
63 | vpMonth.setCurrentItem(currentIndex+1, true);
64 | else Toast.makeText(this, "the end month", Toast.LENGTH_SHORT).show();
65 | }
66 |
67 | @Override
68 | public void clickPrevMonthDay(SCMonth currentMonth) {
69 | int currentIndex = months.indexOf(currentMonth);
70 | if(currentIndex-1 >= 0)
71 | vpMonth.setCurrentItem(currentIndex-1, true);
72 | else Toast.makeText(this, "the start month", Toast.LENGTH_SHORT).show();
73 | }
74 |
75 | class MonthFragmentAdapter extends FragmentPagerAdapter{
76 |
77 | List fragments;
78 |
79 | public MonthFragmentAdapter(FragmentManager fm, List fragments) {
80 | super(fm);
81 | this.fragments = fragments;
82 | }
83 |
84 | @Override
85 | public Fragment getItem(int position) {
86 | return fragments.get(position);
87 | }
88 |
89 | @Override
90 | public int getCount() {
91 | return fragments.size();
92 | }
93 | }
94 |
95 | public static final class MonthFragment extends Fragment{
96 |
97 | public static Fragment newInstance(SCMonth month){
98 | Fragment fragment = new MonthFragment();
99 | Bundle bundle = new Bundle();
100 | bundle.putParcelable("month", month);
101 | fragment.setArguments(bundle);
102 | return fragment;
103 | }
104 |
105 | @Nullable
106 | @Override
107 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
108 | return inflater.inflate(R.layout.item_vp, container, false);
109 | }
110 |
111 | @Override
112 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
113 | super.onViewCreated(view, savedInstanceState);
114 | final MonthView monthView = (MonthView) view.findViewById(R.id.scMv);
115 | final SCMonth month = getArguments().getParcelable("month");
116 | monthView.setSCMonth(month);
117 | monthView.setMonthDayClickListener(new MonthView.OnMonthDayClickListener() {
118 | @Override
119 | public void onMonthDayClick(FullDay day) {
120 | if(SCDateUtils.isPrevMonthDay(monthView.getYear(), monthView.getMonth(),
121 | day.getYear(), day.getMonth())){
122 | clickPrevMonthDay(month);
123 | }else if(SCDateUtils.isNextMonthDay(monthView.getYear(), monthView.getMonth(),
124 | day.getYear(), day.getMonth())){
125 | clickNextMonthDay(month);
126 | }else{
127 | monthView.clearSelectedDays();
128 | monthView.addSelectedDay(day);
129 | }
130 | }
131 | });
132 | }
133 |
134 | private void clickNextMonthDay(SCMonth month) {
135 | Activity activity = getActivity();
136 | if(activity instanceof Protocol){
137 | Protocol protocol = (Protocol)activity;
138 | protocol.clickNextMonthDay(month);
139 | }
140 | }
141 |
142 | private void clickPrevMonthDay(SCMonth month) {
143 | Activity activity = getActivity();
144 | if(activity instanceof Protocol){
145 | Protocol protocol = (Protocol)activity;
146 | protocol.clickPrevMonthDay(month);
147 | }
148 | }
149 | }
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/drawable_custom_dayview_text_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_custom_dayview_text_bg_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_custom_dayview_text_bg_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_apple_calendar.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
17 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_custom_decor.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
22 |
23 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_custom_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
25 |
26 |
33 |
34 |
41 |
42 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
23 |
24 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_normal_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
25 |
26 |
33 |
34 |
42 |
43 |
50 |
51 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scrolling.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_single_month_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
22 |
23 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_vp.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
23 |
24 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_apple_calendar.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
14 |
15 |
25 |
26 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_calendar.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
22 |
23 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_vp.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_dayview_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_dayview_decor_custom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_monday_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
17 |
18 |
25 |
26 |
33 |
34 |
41 |
42 |
49 |
57 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_saturday_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
18 |
26 |
27 |
34 |
35 |
42 |
43 |
50 |
51 |
58 |
59 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_sunday_start.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
27 |
28 |
35 |
36 |
43 |
44 |
51 |
52 |
59 |
60 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_horizontal_decor.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_vertical_decor.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_mode.xml:
--------------------------------------------------------------------------------
1 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_normal.xml:
--------------------------------------------------------------------------------
1 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 日期选择器
4 |
5 | 日
6 | 一
7 | 二
8 | 三
9 | 四
10 | 五
11 | 六
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 180dp
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | CalendarSelector
3 |
4 | SUN
5 | MON
6 | TUE
7 | WED
8 | THU
9 | FRI
10 | SAT
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/art/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/art/1.png
--------------------------------------------------------------------------------
/art/preview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/art/preview.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter{
6 | url "http://jcenter.bintray.com/"
7 | }
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:2.1.0'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter{
20 | url "http://jcenter.bintray.com/"
21 | }
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
29 | ext{
30 | compileSdkVersion = 23
31 | buildToolsVersion = "23.0.2"
32 | minSdkVersion = 8
33 | targetSdkVersion = 23
34 | appcompatVersion = "23.1.1"
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | org.gradle.jvmargs=-XX:MaxPermSize=512m
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TUBB/CalendarSelector/3df98fa2019cb6bbe3b7df8be6c92b95f9aa7700/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release' // must be applied after your artifact generating plugin (eg. java / com.android.library)
3 |
4 | buildscript {
5 | repositories {
6 | jcenter {
7 | url "http://jcenter.bintray.com/"
8 | }
9 | }
10 | dependencies {
11 | classpath 'com.novoda:bintray-release:0.3.4'
12 | }
13 | }
14 |
15 | android {
16 | compileSdkVersion rootProject.compileSdkVersion
17 | buildToolsVersion rootProject.buildToolsVersion
18 |
19 | defaultConfig {
20 | minSdkVersion rootProject.minSdkVersion
21 | targetSdkVersion rootProject.targetSdkVersion
22 | versionCode 23
23 | versionName "0.2.3"
24 | }
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 | }
32 |
33 | dependencies {
34 | compile fileTree(dir: 'libs', include: ['*.jar'])
35 | provided 'com.android.support:appcompat-v7:'+rootProject.appcompatVersion
36 | provided 'com.android.support:recyclerview-v7:'+rootProject.appcompatVersion
37 | }
38 |
39 | publish {
40 | userOrg = 'tubb'
41 | groupId = 'com.tubb.calendarselector.library'
42 | artifactId = 'calendar-selector'
43 | publishVersion = '0.2.3'
44 | desc = 'A calender selector'
45 | website = 'https://github.com/TUBB/CalendarSelector'
46 | }
47 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/tubingbing/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/custom/DayViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 | import com.tubb.calendarselector.library.FullDay;
8 |
9 | /**
10 | * Created by tubingbing on 16/4/13.
11 | */
12 | public abstract class DayViewHolder {
13 |
14 | protected Context mContext;
15 | protected View dayView;
16 |
17 | public DayViewHolder(View dayView){
18 | this.dayView = dayView;
19 | mContext = dayView.getContext();
20 | }
21 |
22 | public View getDayView() {
23 | return dayView;
24 | }
25 |
26 | public abstract void setCurrentMonthDayText(FullDay day, boolean isSelected);
27 | public abstract void setPrevMonthDayText(FullDay day);
28 | public abstract void setNextMonthDayText(FullDay day);
29 | }
30 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/custom/DayViewInflater.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.custom;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.tubb.calendarselector.library.FullDay;
10 |
11 | /**
12 | * Created by tubingbing on 16/4/13.
13 | */
14 | public abstract class DayViewInflater {
15 |
16 | protected Context mContext;
17 | protected LayoutInflater mLayoutInflater;
18 |
19 | public DayViewInflater(Context context){
20 | mContext = context;
21 | mLayoutInflater = LayoutInflater.from(mContext);
22 | }
23 |
24 | /**
25 | * inflate day view
26 | * @param container MonthView
27 | * @return day view
28 | */
29 | public abstract DayViewHolder inflateDayView(ViewGroup container);
30 |
31 | public Decor inflateHorizontalDecor(ViewGroup container, int row, int totalRow){
32 | return null;
33 | }
34 |
35 | public Decor inflateVerticalDecor(ViewGroup container, int col, int totalCol){
36 | return null;
37 | }
38 |
39 | protected int dip2px(Context context, float dpValue) {
40 | final float scale = context.getResources().getDisplayMetrics().density;
41 | return (int) (dpValue * scale + 0.5f);
42 | }
43 |
44 | public boolean isShowHorizontalDecor(int row, int realRowCount) {
45 | return true;
46 | }
47 |
48 | public boolean isShowVerticalDecorDecor(int col, int realColCount) {
49 | return true;
50 | }
51 |
52 | public static class Decor{
53 |
54 | private boolean showDecor = true;
55 | private View decorView;
56 |
57 | public Decor(View decorView){
58 | this.decorView = decorView;
59 | }
60 |
61 | public View getDecorView() {
62 | return decorView;
63 | }
64 |
65 | public boolean isShowDecor() {
66 | return showDecor;
67 | }
68 |
69 | public void setShowDecor(boolean showDecor) {
70 | this.showDecor = showDecor;
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/CalendarSelector.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import android.os.Parcel;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ListView;
9 |
10 | import java.util.ArrayList;
11 | import java.util.Calendar;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by tubingbing on 16/2/4.
16 | */
17 | public class CalendarSelector extends SingleMonthSelector {
18 |
19 | private static final String TAG = "mv";
20 | private static final int LISTENER_HOLDER_TAG_KEY = "LISTENER_HOLDER_TAG_KEY".hashCode();
21 | protected List dataList;
22 |
23 | public CalendarSelector(List dataList, @Mode int mode){
24 | super(null, mode);
25 | this.dataList = dataList;
26 | }
27 |
28 | @Override
29 | public void addSelectedSegment(FullDay startDay, FullDay endDay){
30 | if (mode == INTERVAL) throw new IllegalArgumentException("Just used with SEGMENT mode!!!");
31 | if (startDay == null || endDay == null) throw new IllegalArgumentException("startDay or endDay can't be null");
32 | Calendar startCalendar = Calendar.getInstance();
33 | Calendar endCalendar = Calendar.getInstance();
34 | startCalendar.set(Calendar.YEAR, startDay.getYear());
35 | startCalendar.set(Calendar.MONTH, startDay.getMonth() - 1);
36 | startCalendar.set(Calendar.DAY_OF_MONTH, startDay.getDay());
37 | endCalendar.set(Calendar.YEAR, endDay.getYear());
38 | endCalendar.set(Calendar.MONTH, endDay.getMonth() - 1);
39 | endCalendar.set(Calendar.DAY_OF_MONTH, endDay.getDay());
40 | if (startCalendar.getTime().getTime() > endCalendar.getTime().getTime())
41 | throw new IllegalArgumentException("startDay > endDay not support");
42 | int startDayPosition = dataList.indexOf(new SCMonth(startDay.getYear(), startDay.getMonth()));
43 | int endDayPosition = dataList.indexOf(new SCMonth(endDay.getYear(), endDay.getMonth()));
44 | startSelectedRecord = new SelectedRecord();
45 | startSelectedRecord.position = startDayPosition;
46 | startSelectedRecord.day = startDay;
47 |
48 | endSelectedRecord = new SelectedRecord();
49 | endSelectedRecord.position = endDayPosition;
50 | endSelectedRecord.day = endDay;
51 |
52 | segmentMonthSelected(null, false);
53 | }
54 |
55 | @Override
56 | public void addSelectedInterval(FullDay day){
57 | if (mode == SEGMENT) throw new IllegalArgumentException("Just used with INTERVAL mode!!!");
58 | if (day == null) throw new IllegalArgumentException("day can't be null!!!");
59 | addSelectedDayToMonth(day);
60 | }
61 |
62 | @Override
63 | public void addSelectedInterval(List selectedDays){
64 | if (mode == SEGMENT) throw new IllegalArgumentException("Just used with INTERVAL mode!!!");
65 | if (selectedDays == null) throw new IllegalArgumentException("selectedDays can't be null!!!");
66 | for (FullDay day : selectedDays) {
67 | addSelectedDayToMonth(day);
68 | }
69 | }
70 |
71 | @Override
72 | protected void addSelectedDayToMonth(FullDay day) {
73 | SCMonth comparedMonth = new SCMonth(day.getYear(), day.getMonth());
74 | if (dataList.contains(comparedMonth)){
75 | SCMonth sourceMonth = dataList.get(dataList.indexOf(comparedMonth));
76 | sDays.add(day);
77 | sourceMonth.addSelectedDay(day);
78 | }else {
79 | throw new IllegalArgumentException("The day not belong to any month!!!");
80 | }
81 | }
82 |
83 | public void bind(final ViewGroup container, final MonthView monthView, final int position){
84 | if(container == null || monthView == null || position < 0)
85 | throw new IllegalArgumentException("Invalid params of bind(final ViewGroup container, final SSMonthView monthView, final int position) method");
86 | if(this.mode == INTERVAL && this.intervalSelectListener == null)
87 | throw new IllegalArgumentException("Please set IntervalSelectListener for Mode.INTERVAL mode");
88 | if(this.mode == SEGMENT && this.segmentSelectListener == null)
89 | throw new IllegalArgumentException("Please set SegmentSelectListener for Mode.SEGMENT mode");
90 | if(container instanceof ListView) throw new IllegalArgumentException("Not support ListView yet");
91 | ListenerHolder listenerHolder = (ListenerHolder) monthView.getTag(LISTENER_HOLDER_TAG_KEY);
92 | if(listenerHolder == null){
93 | listenerHolder = new ListenerHolder();
94 | monthView.setTag(LISTENER_HOLDER_TAG_KEY, listenerHolder);
95 | }
96 | listenerHolder.container = container;
97 | listenerHolder.monthView = monthView;
98 | listenerHolder.position = position;
99 | monthView.setMonthDayClickListener(listenerHolder);
100 | }
101 |
102 | class ListenerHolder implements MonthView.OnMonthDayClickListener{
103 |
104 | ViewGroup container;
105 | MonthView monthView;
106 | int position;
107 |
108 | @Override
109 | public void onMonthDayClick(FullDay day) {
110 | if(!SCDateUtils.isMonthDay(monthView.getYear(), monthView.getMonth(),
111 | day.getYear(), day.getMonth()))
112 | return;
113 | switch (mode){
114 | case INTERVAL:
115 | intervalSelect(monthView, day);
116 | break;
117 | case SEGMENT:
118 | segmentSelect(container, monthView, day, position);
119 | break;
120 | }
121 | }
122 | }
123 |
124 | private void segmentSelect(ViewGroup container, MonthView monthView, FullDay ssDay, int position) {
125 |
126 | if(segmentSelectListener.onInterceptSelect(ssDay)) return;
127 |
128 | if(!startSelectedRecord.isRecord() && !endSelectedRecord.isRecord()){ // init status
129 | startSelectedRecord.position = position;
130 | startSelectedRecord.day = ssDay;
131 | monthView.addSelectedDay(ssDay);
132 | }else if(startSelectedRecord.isRecord() && !endSelectedRecord.isRecord()){ // start day is ok, but end day not
133 | if(startSelectedRecord.position < position){ // click later month
134 | if(segmentSelectListener.onInterceptSelect(startSelectedRecord.day, ssDay)) return;
135 | endSelectedRecord.position = position;
136 | endSelectedRecord.day = ssDay;
137 | segmentMonthSelected(container, true);
138 | }else if(startSelectedRecord.position > position){ // click before month
139 | if(segmentSelectListener.onInterceptSelect(ssDay, startSelectedRecord.day)) return;
140 | endSelectedRecord.position = startSelectedRecord.position;
141 | endSelectedRecord.day = startSelectedRecord.day;
142 | startSelectedRecord.position = position;
143 | startSelectedRecord.day = ssDay;
144 | segmentMonthSelected(container, true);
145 | }else{ // click the same month
146 | if(startSelectedRecord.day.getDay() != ssDay.getDay()){
147 | if(startSelectedRecord.day.getDay() < ssDay.getDay()){
148 | if(segmentSelectListener.onInterceptSelect(startSelectedRecord.day, ssDay)) return;
149 | for (int day = startSelectedRecord.day.getDay(); day <= ssDay.getDay(); day++){
150 | monthView.addSelectedDay(new FullDay(monthView.getYear(), monthView.getMonth(), day));
151 | }
152 | endSelectedRecord.position = position;
153 | endSelectedRecord.day = ssDay;
154 | }else if(startSelectedRecord.day.getDay() > ssDay.getDay()){
155 | if(segmentSelectListener.onInterceptSelect(ssDay, startSelectedRecord.day)) return;
156 | for (int day = ssDay.getDay(); day <= startSelectedRecord.day.getDay(); day++){
157 | monthView.addSelectedDay(new FullDay(monthView.getYear(), monthView.getMonth(), day));
158 | }
159 | endSelectedRecord.position = position;
160 | endSelectedRecord.day = startSelectedRecord.day;
161 | startSelectedRecord.day = ssDay;
162 | }
163 | monthView.invalidate();
164 | segmentSelectListener.onSegmentSelect(startSelectedRecord.day, endSelectedRecord.day);
165 | }else{
166 | // selected the same day when the end day is not selected
167 | segmentSelectListener.selectedSameDay(ssDay);
168 | monthView.clearSelectedDays();
169 | startSelectedRecord.reset();
170 | endSelectedRecord.reset();
171 | }
172 | }
173 |
174 | }else if(startSelectedRecord.isRecord() && endSelectedRecord.isRecord()){ // start day and end day is ok
175 | dataList.get(startSelectedRecord.position).getSelectedDays().clear();
176 | invalidate(container, startSelectedRecord.position);
177 |
178 | dataList.get(endSelectedRecord.position).getSelectedDays().clear();
179 | invalidate(container, endSelectedRecord.position);
180 |
181 | int startSelectedPosition = startSelectedRecord.position;
182 | int endSelectedPosition = endSelectedRecord.position;
183 |
184 | if(endSelectedPosition - startSelectedPosition > 1){
185 | do {
186 | startSelectedPosition++;
187 | dataList.get(startSelectedPosition).getSelectedDays().clear();
188 | invalidate(container, startSelectedPosition);
189 | }while (startSelectedPosition < endSelectedPosition);
190 | }
191 |
192 | startSelectedRecord.position = position;
193 | startSelectedRecord.day = ssDay;
194 | dataList.get(startSelectedRecord.position).addSelectedDay(startSelectedRecord.day);
195 | invalidate(container, position);
196 |
197 | endSelectedRecord.reset();
198 | }
199 | }
200 |
201 | private void invalidate(ViewGroup container, int position){
202 | if(position >= 0) {
203 | if (container instanceof RecyclerView){
204 | RecyclerView rv = (RecyclerView)container;
205 | rv.getAdapter().notifyItemChanged(position);
206 | }else if (container instanceof ListView){
207 | Log.e(TAG, "The ListView not support yet!!!");
208 | }else {
209 | View childView = container.getChildAt(position);
210 | List unvisited = new ArrayList<>();
211 | unvisited.add(childView);
212 | while (!unvisited.isEmpty()) {
213 | View child = unvisited.remove(0);
214 | if (!(child instanceof ViewGroup)) {
215 | continue;
216 | }
217 | ViewGroup group = (ViewGroup) child;
218 | if(group instanceof MonthView){
219 | MonthView monthView = (MonthView) group;
220 | monthView.refresh();
221 | break;
222 | }
223 | final int childCount = group.getChildCount();
224 | for (int i=0; i endSelectedRecord.day.getDay()){
244 | for (int day = endSelectedRecord.day.getDay(); day <= startSelectedRecord.day.getDay(); day++){
245 | targetMonth.addSelectedDay(new FullDay(targetMonth.getYear(), targetMonth.getMonth(), day));
246 | }
247 | }
248 | }else{
249 | targetMonth.addSelectedDay(startSelectedRecord.day);
250 | }
251 | return;
252 | }
253 |
254 | SCMonth startMonth = dataList.get(startSelectedRecord.position);
255 | int startSelectedMonthDayCount = SCDateUtils.getDayCountOfMonth(startMonth.getYear(), startMonth.getMonth());
256 | for (int day = startSelectedRecord.day.getDay(); day <= startSelectedMonthDayCount; day++){
257 | startMonth.addSelectedDay(new FullDay(startMonth.getYear(), startMonth.getMonth(), day));
258 | }
259 | if (shouldRefreshView) invalidate(container, startSelectedRecord.position);
260 |
261 | int startSelectedPosition = startSelectedRecord.position;
262 | int endSelectedPosition = endSelectedRecord.position;
263 |
264 | while (endSelectedPosition - startSelectedPosition > 1){
265 | startSelectedPosition++;
266 | SCMonth segmentMonth = dataList.get(startSelectedPosition);
267 | int segmentSelectedMonthDayCount = SCDateUtils.getDayCountOfMonth(segmentMonth.getYear(), segmentMonth.getMonth());
268 | for (int day = 1; day <= segmentSelectedMonthDayCount; day++) {
269 | segmentMonth.addSelectedDay(new FullDay(segmentMonth.getYear(), segmentMonth.getMonth(), day));
270 | }
271 | if (shouldRefreshView) invalidate(container, startSelectedPosition);
272 | }
273 |
274 | SCMonth endMonth = dataList.get(endSelectedRecord.position);
275 | for (int day = 1; day <= endSelectedRecord.day.getDay(); day++){
276 | endMonth.addSelectedDay(new FullDay(endMonth.getYear(), endMonth.getMonth(), day));
277 | }
278 | if (shouldRefreshView) invalidate(container, endSelectedRecord.position);
279 |
280 | if (shouldRefreshView) segmentSelectListener.onSegmentSelect(startSelectedRecord.day, endSelectedRecord.day);
281 | }
282 |
283 | /**
284 | * get the first selected day
285 | * @return the first selected day, may be null
286 | */
287 | public FullDay getStartDay(){
288 | return startSelectedRecord.day;
289 | }
290 |
291 | /**
292 | * get the last selected day
293 | * @return the last selected day, may be null
294 | */
295 | public FullDay getEndDay(){
296 | return endSelectedRecord.day;
297 | }
298 |
299 | public List getDataList() {
300 | return dataList;
301 | }
302 |
303 | @Override
304 | public int describeContents() {
305 | return 0;
306 | }
307 |
308 | @Override
309 | public void writeToParcel(Parcel dest, int flags) {
310 | super.writeToParcel(dest, flags);
311 | dest.writeTypedList(dataList);
312 | }
313 |
314 | protected CalendarSelector(Parcel in) {
315 | super(in);
316 | this.dataList = in.createTypedArrayList(SCMonth.CREATOR);
317 | }
318 |
319 | public static final Creator CREATOR = new Creator() {
320 | public CalendarSelector createFromParcel(Parcel source) {
321 | return new CalendarSelector(source);
322 | }
323 |
324 | public CalendarSelector[] newArray(int size) {
325 | return new CalendarSelector[size];
326 | }
327 | };
328 | }
329 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/DefaultDayViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import android.content.pm.PackageInfo;
4 | import android.content.pm.PackageManager;
5 | import android.support.v4.content.ContextCompat;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import com.tubb.calendarselector.custom.DayViewHolder;
10 |
11 | /**
12 | * Created by tubingbing on 16/4/13.
13 | */
14 | public final class DefaultDayViewHolder extends DayViewHolder {
15 |
16 | protected TextView tvDay;
17 | private int mPrevMonthDayTextColor;
18 | private int mNextMonthDayTextColor;
19 |
20 | public DefaultDayViewHolder(View dayView) {
21 | super(dayView);
22 | tvDay = (TextView) dayView.findViewById(R.id.tvDay);
23 | int targetSDKVersion = 0;
24 | try {
25 | PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
26 | targetSDKVersion = packageInfo.applicationInfo.targetSdkVersion;
27 | } catch (PackageManager.NameNotFoundException e) {}
28 |
29 | if (targetSDKVersion >= 23) {
30 | mPrevMonthDayTextColor = ContextCompat.getColor(mContext, R.color.c_999999);
31 | } else {
32 | mPrevMonthDayTextColor = mContext.getResources().getColor(R.color.c_999999);
33 | }
34 |
35 | if (targetSDKVersion >= 23) {
36 | mNextMonthDayTextColor = ContextCompat.getColor(mContext, R.color.c_999999);
37 | } else {
38 | mNextMonthDayTextColor = mContext.getResources().getColor(R.color.c_999999);
39 | }
40 | }
41 |
42 | @Override
43 | public void setCurrentMonthDayText(FullDay day, boolean isSelected) {
44 | tvDay.setText(String.valueOf(day.getDay()));
45 | tvDay.setSelected(isSelected);
46 | }
47 |
48 | @Override
49 | public void setPrevMonthDayText(FullDay day) {
50 | tvDay.setTextColor(mPrevMonthDayTextColor);
51 | tvDay.setText(String.valueOf(day.getDay()));
52 | }
53 |
54 | @Override
55 | public void setNextMonthDayText(FullDay day) {
56 | tvDay.setTextColor(mNextMonthDayTextColor);
57 | tvDay.setText(String.valueOf(day.getDay()));
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/DefaultDayViewInflater.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import android.content.Context;
4 | import android.content.pm.PackageInfo;
5 | import android.content.pm.PackageManager;
6 | import android.graphics.Paint;
7 | import android.os.Build;
8 | import android.support.v4.content.ContextCompat;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 |
12 | import com.tubb.calendarselector.custom.DayViewHolder;
13 | import com.tubb.calendarselector.custom.DayViewInflater;
14 |
15 | /**
16 | * Created by tubingbing on 16/4/13.
17 | */
18 | public final class DefaultDayViewInflater extends DayViewInflater {
19 |
20 | private Paint mDecorPaint;
21 | private int mDecorWidth; // px
22 |
23 | public DefaultDayViewInflater(Context context) {
24 | super(context);
25 | mDecorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
26 | mDecorWidth = dip2px(mContext, 0.5f);
27 | int targetSDKVersion = 0;
28 | try {
29 | PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
30 | targetSDKVersion = packageInfo.applicationInfo.targetSdkVersion;
31 | } catch (PackageManager.NameNotFoundException e) {}
32 | if (targetSDKVersion >= 23) {
33 | mDecorPaint.setColor(ContextCompat.getColor(mContext, R.color.c_dddddd));
34 | } else {
35 | mDecorPaint.setColor(context.getResources().getColor(R.color.c_dddddd));
36 | }
37 | mDecorPaint.setStrokeWidth(mDecorWidth);
38 | }
39 |
40 | @Override
41 | public DayViewHolder inflateDayView(ViewGroup container) {
42 | View dayView = mLayoutInflater.inflate(R.layout.layout_dayview_default, container, false);
43 | return new DefaultDayViewHolder(dayView);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/FullDay.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import android.support.annotation.IntDef;
6 |
7 | import com.tubb.calendarselector.custom.DayViewHolder;
8 |
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 |
12 | /**
13 | * Created by tubingbing on 16/3/1.
14 | */
15 | public class FullDay implements Parcelable {
16 |
17 | public static final int WEEK_1 = 1;
18 | public static final int WEEK_2 = 2;
19 | public static final int WEEK_3 = 3;
20 | public static final int WEEK_4 = 4;
21 | public static final int WEEK_5 = 5;
22 | public static final int WEEK_6 = 6;
23 | public static final int WEEK_7 = 7;
24 |
25 | protected int year;
26 | protected int month;
27 | protected int day;
28 | protected int weekOf;
29 |
30 | public FullDay(int year, int month, int day) {
31 | this.year = year;
32 | this.month = month;
33 | this.day = day;
34 | }
35 |
36 | public int getYear() {
37 | return year;
38 | }
39 |
40 | public void setYear(int year) {
41 | this.year = year;
42 | }
43 |
44 | public int getMonth() {
45 | return month;
46 | }
47 |
48 | public void setMonth(int month) {
49 | this.month = month;
50 | }
51 |
52 | public int getDay() {
53 | return day;
54 | }
55 |
56 | public void setDay(int day) {
57 | this.day = day;
58 | }
59 |
60 | public void setWeekOf(int weekOf) {
61 | this.weekOf = weekOf;
62 | }
63 |
64 | @Override
65 | public boolean equals(Object o) {
66 | if (this == o) return true;
67 | if (o == null || getClass() != o.getClass()) return false;
68 |
69 | FullDay fullDay = (FullDay) o;
70 |
71 | if (year != fullDay.year) return false;
72 | if (month != fullDay.month) return false;
73 | return day == fullDay.day;
74 |
75 | }
76 |
77 | @Override
78 | public int hashCode() {
79 | int result = year;
80 | result = 31 * result + month;
81 | result = 31 * result + day;
82 | return result;
83 | }
84 |
85 | /**
86 | * get the position of week ([1-7])
87 | */
88 | public int getWeekOf() {
89 | return weekOf;
90 | }
91 |
92 | @Override
93 | public String toString() {
94 | return "FullDay{" +
95 | "year=" + year +
96 | ", month=" + month +
97 | ", day=" + day +
98 | ", weekOf=" + weekOf +
99 | '}';
100 | }
101 |
102 | @Override
103 | public int describeContents() {
104 | return 0;
105 | }
106 |
107 | @Override
108 | public void writeToParcel(Parcel dest, int flags) {
109 | dest.writeInt(this.year);
110 | dest.writeInt(this.month);
111 | dest.writeInt(this.day);
112 | dest.writeInt(this.weekOf);
113 | }
114 |
115 | protected FullDay(Parcel in) {
116 | this.year = in.readInt();
117 | this.month = in.readInt();
118 | this.day = in.readInt();
119 | this.weekOf = in.readInt();
120 | }
121 |
122 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
123 | @Override
124 | public FullDay createFromParcel(Parcel source) {
125 | return new FullDay(source);
126 | }
127 |
128 | @Override
129 | public FullDay[] newArray(int size) {
130 | return new FullDay[size];
131 | }
132 | };
133 | }
134 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/IntervalSelectListener.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by tubingbing on 16/2/24.
7 | */
8 | public abstract class IntervalSelectListener {
9 | public abstract void onIntervalSelect(List selectedDays);
10 | public boolean onInterceptSelect(List selectedDays, FullDay selectingDay){
11 | return false;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/SCDateUtils.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Calendar;
5 | import java.util.List;
6 |
7 | /**
8 | * Created by tubingbing on 16/1/20.
9 | */
10 | public class SCDateUtils {
11 |
12 | private static final String[] SUNDAY_WEEKS = new String[]{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
13 | private static final String[] MONDAY_WEEKS = new String[]{"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
14 | private static final String[] SATURDAY_WEEKS = new String[]{"SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI"};
15 |
16 | public static int getCurrentDay(){
17 | Calendar calendar = Calendar.getInstance();
18 | return calendar.get(Calendar.DAY_OF_MONTH);
19 | }
20 |
21 | public static int getCurrentMonth(){
22 | Calendar calendar = Calendar.getInstance();
23 | return calendar.get(Calendar.MONTH) + 1;
24 | }
25 |
26 | public static int getCurrentYear(){
27 | Calendar calendar = Calendar.getInstance();
28 | return calendar.get(Calendar.YEAR);
29 | }
30 |
31 | public static int mapDayOfWeekInMonth(int sundayPosition, int mappingWeek){
32 | if(mappingWeek <= 0 || mappingWeek == SCMonth.SUNDAY_OF_WEEK) return sundayPosition;
33 | else{
34 | String sundayPositionDesc = SUNDAY_WEEKS[sundayPosition - 1];
35 | if(mappingWeek == SCMonth.MONDAY_OF_WEEK){ // monday is the start day of a week
36 | for (int i = 0; i < MONDAY_WEEKS.length; i++) {
37 | if(sundayPositionDesc.equals(MONDAY_WEEKS[i])) return i+1;
38 | }
39 | }else if(mappingWeek == SCMonth.SATURDAY_OF_WEEK){ // saturday is the start day of a week
40 | for (int i = 0; i < SATURDAY_WEEKS.length; i++) {
41 | if(sundayPositionDesc.equals(SATURDAY_WEEKS[i])) return i+1;
42 | }
43 | }
44 | }
45 | return sundayPosition;
46 | }
47 |
48 | /**
49 | * the first day of month
50 | * @param year
51 | * @param month
52 | * @return week position
53 | */
54 | public static int getDayOfWeekInMonth(int year, int month){
55 | Calendar calendar = Calendar.getInstance();
56 | calendar.set(Calendar.YEAR, year);
57 | calendar.set(Calendar.MONTH, month-1);
58 | calendar.set(Calendar.DATE, 1);
59 | return calendar.get(Calendar.DAY_OF_WEEK);
60 | }
61 |
62 | public static int getDayCountOfMonth(int year, int month){
63 | int[] arr = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
64 | int days = 0;
65 | if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { // leap year
66 | arr[1] = 29;
67 | }
68 | try {
69 | days = arr[month - 1];
70 | } catch (Exception e) {
71 | e.printStackTrace();
72 | }
73 | return days;
74 | }
75 |
76 | public static SCMonth prevMonth(int year, int month){
77 | if(month == 1){
78 | year -= 1;
79 | month = 12;
80 | }else{
81 | month -= 1;
82 | }
83 | return new SCMonth(year, month);
84 | }
85 |
86 | public static SCMonth nextMonth(int year, int month){
87 | if(month == 12){
88 | year += 1;
89 | month = 1;
90 | }else{
91 | month += 1;
92 | }
93 | return new SCMonth(year, month);
94 | }
95 |
96 | public static boolean isPrevMonthDay(int year, int month, int otherYear, int otherMonth){
97 | if((year - otherYear) == 1 && otherMonth == 12) return true;
98 | if(otherYear != year) return false;
99 | if(otherMonth + 1 != month) return false;
100 | return true;
101 | }
102 |
103 | public static boolean isMonthDay(int year, int month, int otherYear, int otherMonth){
104 | if(otherYear != year) return false;
105 | if(otherMonth != month) return false;
106 | return true;
107 | }
108 |
109 | public static boolean isNextMonthDay(int year, int month, int otherYear, int otherMonth){
110 | if((otherYear - year) == 1 && otherMonth == 1) return true;
111 | if(otherYear != year) return false;
112 | if(otherMonth - 1 != month) return false;
113 | return true;
114 | }
115 |
116 | public static boolean isToday(int year, int month, int day) {
117 | return year == getCurrentYear() && month == getCurrentMonth() && day == getCurrentDay();
118 | }
119 |
120 | /**
121 | * calculate day count
122 | * @param startYear start year
123 | * @param startMonth start month
124 | * @param startDay start day
125 | * @param endYear end year
126 | * @param endMonth end month
127 | * @param endDay end day
128 | * @return day count
129 | */
130 | public static int countDays(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay) {
131 | Calendar startC = Calendar.getInstance();
132 | startC.set(Calendar.YEAR, startYear);
133 | startC.set(Calendar.MONTH, startMonth-1);
134 | startC.set(Calendar.DAY_OF_MONTH, startDay);
135 | Calendar endC = Calendar.getInstance();
136 | endC.set(Calendar.YEAR, endYear);
137 | endC.set(Calendar.MONTH, endMonth-1);
138 | endC.set(Calendar.DAY_OF_MONTH, endDay);
139 | return (int) ((endC.getTimeInMillis() - startC.getTimeInMillis()) / 86400000 + 1);
140 | }
141 |
142 | public static List generateMonths(int startYear, int endYear){
143 | return generateMonths(startYear, 1, endYear, 12, SCMonth.SUNDAY_OF_WEEK);
144 | }
145 |
146 | public static List generateMonths(int startYear, int endYear, @SCMonth.WeekType int weekType){
147 | return generateMonths(startYear, 1, endYear, 12, weekType);
148 | }
149 |
150 | public static List generateMonths(int startYear, int startMonth, int endYear, int endMonth) {
151 | return generateMonths(startYear, startMonth, endYear, endMonth, SCMonth.SUNDAY_OF_WEEK);
152 | }
153 |
154 | public static List generateMonths(int startYear, int startMonth, int endYear, int endMonth, @SCMonth.WeekType int weekType){
155 |
156 | if(startYear <= 0 || endYear <= 0 || startMonth <= 0 || endMonth <= 0 || startMonth > 12 || endMonth > 12)
157 | throw new IllegalArgumentException("Invalid startYear、startMonth、endYear or endMonth");
158 |
159 | if(startYear > endYear) throw new IllegalArgumentException("startYear must less than endYear");
160 |
161 | if(startYear == endYear && startMonth > endMonth)
162 | throw new IllegalArgumentException("startMonth must less than endMonth when startYear equal to endYear");
163 |
164 | List data = new ArrayList<>();
165 | if(startYear == endYear){
166 | for (int i = startMonth; i <= endMonth; i++) {
167 | data.add(new SCMonth(startYear, i, weekType));
168 | }
169 | }else{
170 | for (int i = startMonth; i <= 12; i++) {
171 | data.add(new SCMonth(startYear, i, weekType));
172 | }
173 | while (endYear - startYear > 1){
174 | startYear++;
175 | for (int i = 1; i <= 12; i++) {
176 | data.add(new SCMonth(startYear, i, weekType));
177 | }
178 | }
179 | for (int i = 1; i <= endMonth; i++) {
180 | data.add(new SCMonth(endYear, i, weekType));
181 | }
182 | }
183 | return data;
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/SCMonth.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import android.support.annotation.IntDef;
6 | import android.util.Log;
7 |
8 | import java.lang.annotation.Retention;
9 | import java.lang.annotation.RetentionPolicy;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | /**
13 | * Created by tubingbing on 16/1/19.
14 | */
15 | public class SCMonth implements Parcelable {
16 |
17 | public static final int SUNDAY_OF_WEEK = 1;
18 | public static final int MONDAY_OF_WEEK = 2;
19 | public static final int SATURDAY_OF_WEEK = 7;
20 | public static final int ROW_COUNT = 6;
21 | public static final int COL_COUNT = 7;
22 |
23 | protected int year;
24 | protected int month;
25 | protected List selectedDays = new ArrayList<>(5);
26 | private FullDay[][] monthDays = new FullDay[ROW_COUNT][COL_COUNT];
27 | private int realRowCount;
28 | private int firstDayOfWeek;
29 | private int firstdayOfWeekPosInMonth;
30 | private int dayCountOfPrevMonth;
31 | private SCMonth prevMonth;
32 | private SCMonth nextMonth;
33 |
34 | public SCMonth(int year, int month, @WeekType int firstDayOfWeek){
35 | this.year = year;
36 | this.month = month;
37 | this.firstDayOfWeek = firstDayOfWeek;
38 | calculateDays();
39 | }
40 |
41 | SCMonth(int year, int month){
42 | this.year = year;
43 | this.month = month;
44 | }
45 |
46 | private void calculateDays() {
47 |
48 | prevMonth = SCDateUtils.prevMonth(getYear(), getMonth());
49 | dayCountOfPrevMonth = SCDateUtils.getDayCountOfMonth(prevMonth.getYear(), prevMonth.getMonth());
50 | nextMonth = SCDateUtils.nextMonth(getYear(), getMonth());
51 | // the first day of month is which week's day
52 | firstdayOfWeekPosInMonth = SCDateUtils.mapDayOfWeekInMonth(SCDateUtils.getDayOfWeekInMonth(getYear(), getMonth()), firstDayOfWeek);
53 | int dayCountOfMonth = SCDateUtils.getDayCountOfMonth(getYear(), getMonth());
54 |
55 | int currentRealRowCount = 0;
56 | int day = 1;
57 | for (int row = 0; row < ROW_COUNT; row++){
58 | boolean isAllRowEmpty = true;
59 | for (int col = 1; col <= COL_COUNT; col++){
60 | int monthPosition = col + row * COL_COUNT;
61 | FullDay oldFullDay = monthDays[row][col-1];
62 | if(monthPosition >= firstdayOfWeekPosInMonth
63 | && monthPosition < firstdayOfWeekPosInMonth + dayCountOfMonth){ // current month
64 | if(oldFullDay == null){
65 | FullDay currentMonthDay = new FullDay(getYear(), getMonth(), day);
66 | monthDays[row][col-1] = currentMonthDay;
67 | }else{
68 | oldFullDay.setYear(getYear());
69 | oldFullDay.setMonth(getMonth());
70 | oldFullDay.setDay(day);
71 | }
72 | day++;
73 | isAllRowEmpty = false;
74 | }else if(monthPosition < firstdayOfWeekPosInMonth){ // prev month
75 | int prevDay = dayCountOfPrevMonth - (firstdayOfWeekPosInMonth - 1 - monthPosition);
76 | if(oldFullDay == null){
77 | FullDay prevMonthDay = new FullDay(prevMonth.getYear(), prevMonth.getMonth(), prevDay);
78 | monthDays[row][col-1] = prevMonthDay;
79 | }else{
80 | oldFullDay.setYear(prevMonth.getYear());
81 | oldFullDay.setMonth(prevMonth.getMonth());
82 | oldFullDay.setDay(prevDay);
83 | }
84 | }else if(monthPosition >= firstdayOfWeekPosInMonth + dayCountOfMonth){ // next month
85 | if(oldFullDay == null){
86 | FullDay nextMonthDay = new FullDay(nextMonth.getYear(), nextMonth.getMonth(),
87 | monthPosition - (firstdayOfWeekPosInMonth + dayCountOfMonth) + 1);
88 | monthDays[row][col-1] = nextMonthDay;
89 | }else{
90 | oldFullDay.setYear(nextMonth.getYear());
91 | oldFullDay.setMonth(nextMonth.getMonth());
92 | oldFullDay.setDay(monthPosition - (firstdayOfWeekPosInMonth + dayCountOfMonth) + 1);
93 | }
94 | }
95 | monthDays[row][col-1].setWeekOf(col);
96 | }
97 | if(!isAllRowEmpty){
98 | currentRealRowCount++;
99 | }
100 | }
101 |
102 | setRealRowCount(currentRealRowCount);
103 | }
104 |
105 | @Retention(RetentionPolicy.SOURCE)
106 | @IntDef({SUNDAY_OF_WEEK, MONDAY_OF_WEEK, SATURDAY_OF_WEEK})
107 | public @interface WeekType{}
108 |
109 | void setMonthDays(FullDay[][] monthDays) {
110 | this.monthDays = monthDays;
111 | }
112 |
113 | public SCMonth getNextMonth() {
114 | return nextMonth;
115 | }
116 |
117 | public SCMonth getPrevMonth() {
118 | return prevMonth;
119 | }
120 |
121 | public int getDayCountOfPrevMonth() {
122 | return dayCountOfPrevMonth;
123 | }
124 |
125 | public int getFirstdayOfWeekPosInMonth() {
126 | return firstdayOfWeekPosInMonth;
127 | }
128 |
129 | public FullDay[][] getMonthDays() {
130 | return monthDays;
131 | }
132 |
133 | public void setRealRowCount(int realRowCount) {
134 | this.realRowCount = realRowCount;
135 | }
136 |
137 | public int getRealRowCount() {
138 | return realRowCount;
139 | }
140 |
141 | public void setMonth(int month) {
142 | this.month = month;
143 | }
144 |
145 | public int getMonth() {
146 | return month;
147 | }
148 |
149 | public void setYear(int year) {
150 | this.year = year;
151 | }
152 |
153 | public int getYear() {
154 | return year;
155 | }
156 |
157 | public void setSelectedDays(List selectedDays) {
158 | this.selectedDays = selectedDays;
159 | }
160 |
161 | protected List getSelectedDays() {
162 | return selectedDays;
163 | }
164 |
165 | public void addSelectedDay(FullDay fullDay){
166 | getSelectedDays().add(fullDay);
167 | }
168 |
169 | @Override
170 | public boolean equals(Object o) {
171 | if (this == o) return true;
172 | if (o == null || getClass() != o.getClass()) return false;
173 |
174 | SCMonth SCMonth = (SCMonth) o;
175 | if (year != SCMonth.year) return false;
176 | return month == SCMonth.month;
177 | }
178 |
179 | @Override
180 | public int hashCode() {
181 | int result = year;
182 | result = 31 * result + month;
183 | return result;
184 | }
185 |
186 | @Override
187 | public String toString() {
188 | return year + "-" + month;
189 | }
190 |
191 | @Override
192 | public int describeContents() {
193 | return 0;
194 | }
195 |
196 | @Override
197 | public void writeToParcel(Parcel dest, int flags) {
198 | dest.writeInt(this.year);
199 | dest.writeInt(this.month);
200 | dest.writeTypedList(selectedDays);
201 | }
202 |
203 | protected SCMonth(Parcel in) {
204 | this.year = in.readInt();
205 | this.month = in.readInt();
206 | this.selectedDays = in.createTypedArrayList(FullDay.CREATOR);
207 | calculateDays();
208 | }
209 |
210 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
211 | @Override
212 | public SCMonth createFromParcel(Parcel source) {
213 | return new SCMonth(source);
214 | }
215 |
216 | @Override
217 | public SCMonth[] newArray(int size) {
218 | return new SCMonth[size];
219 | }
220 | };
221 | }
222 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/SegmentSelectListener.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | /**
4 | * Created by tubingbing on 16/2/24.
5 | */
6 | public abstract class SegmentSelectListener {
7 | public abstract void onSegmentSelect(FullDay startDay, FullDay endDay);
8 | public boolean onInterceptSelect(FullDay startDay, FullDay endDay){
9 | return false;
10 | }
11 | public boolean onInterceptSelect(FullDay selectingDay){
12 | return false;
13 | }
14 | public void selectedSameDay(FullDay sameDay){
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tubb/calendarselector/library/SingleMonthSelector.java:
--------------------------------------------------------------------------------
1 | package com.tubb.calendarselector.library;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import android.support.annotation.IntDef;
6 |
7 | import java.util.LinkedList;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by tubingbing on 16/3/2.
12 | */
13 | public class SingleMonthSelector implements Parcelable {
14 |
15 | public static final int INTERVAL = 0;
16 | public static final int SEGMENT = 1;
17 |
18 | protected int mode = -1;
19 | private SCMonth mMonth;
20 | protected SelectedRecord startSelectedRecord = new SelectedRecord();
21 | protected SelectedRecord endSelectedRecord = new SelectedRecord();
22 | protected List sDays = new LinkedList<>();
23 | protected IntervalSelectListener intervalSelectListener;
24 | protected SegmentSelectListener segmentSelectListener;
25 |
26 | public SingleMonthSelector(SCMonth scMonth, @Mode int mode){
27 | mMonth = scMonth;
28 | this.mode = mode;
29 | }
30 |
31 | public void addSelectedSegment(FullDay startDay, FullDay endDay){
32 | if (mode == INTERVAL) throw new IllegalArgumentException("Just used with SEGMENT mode!!!");
33 | if (startDay == null || endDay == null) throw new IllegalArgumentException("startDay or endDay can't be null");
34 | if (startDay.day >= endDay.day) throw new IllegalArgumentException("startDay >= endDay not support");
35 | SCMonth comparedMonthStart = new SCMonth(startDay.getYear(), startDay.getMonth());
36 | if (!mMonth.equals(comparedMonthStart)) throw new IllegalArgumentException("startDay not belong to scMonth");
37 | SCMonth comparedMonthEnd = new SCMonth(endDay.getYear(), endDay.getMonth());
38 | if (!mMonth.equals(comparedMonthEnd)) throw new IllegalArgumentException("endDay not belong to scMonth");
39 | startSelectedRecord.day = startDay;
40 | endSelectedRecord.day = endDay;
41 | mMonth.addSelectedDay(startDay);
42 | mMonth.addSelectedDay(endDay);
43 |
44 | if(startSelectedRecord.day.getDay() < endSelectedRecord.day.getDay()){
45 | for (int day = startSelectedRecord.day.getDay(); day <= endSelectedRecord.day.getDay(); day++){
46 | mMonth.addSelectedDay(new FullDay(mMonth.getYear(), mMonth.getMonth(), day));
47 | }
48 | }else if(startSelectedRecord.day.getDay() > endSelectedRecord.day.getDay()){
49 | for (int day = endSelectedRecord.day.getDay(); day <= startSelectedRecord.day.getDay(); day++){
50 | mMonth.addSelectedDay(new FullDay(mMonth.getYear(), mMonth.getMonth(), day));
51 | }
52 | }
53 | }
54 |
55 | public void addSelectedInterval(FullDay day){
56 | if (mode == SEGMENT) throw new IllegalArgumentException("Just used with INTERVAL mode!!!");
57 | if (day == null) throw new IllegalArgumentException("day can't be null!!!");
58 | addSelectedDayToMonth(day);
59 | }
60 |
61 | public void addSelectedInterval(List selectedDays){
62 | if (mode == SEGMENT) throw new IllegalArgumentException("Just used with INTERVAL mode!!!");
63 | if (selectedDays == null) throw new IllegalArgumentException("selectedDays can't be null!!!");
64 | for (FullDay day : selectedDays) {
65 | addSelectedDayToMonth(day);
66 | }
67 | }
68 |
69 | protected void addSelectedDayToMonth(FullDay day) {
70 | SCMonth comparedMonth = new SCMonth(day.getYear(), day.getMonth());
71 | if (mMonth.equals(comparedMonth)){
72 | mMonth.addSelectedDay(day);
73 | sDays.add(day);
74 | }else {
75 | throw new IllegalArgumentException("The day not belong to any month!!!");
76 | }
77 | }
78 |
79 | public void bind(final MonthView monthView){
80 | if(monthView == null)
81 | throw new IllegalArgumentException("Invalid params of bind(final ViewGroup container, final SSMonthView monthView, final int position) method");
82 | if(this.mode == INTERVAL && this.intervalSelectListener == null)
83 | throw new IllegalArgumentException("Please set IntervalSelectListener for Mode.INTERVAL mode");
84 | if(this.mode == SEGMENT && this.segmentSelectListener == null)
85 | throw new IllegalArgumentException("Please set SegmentSelectListener for Mode.SEGMENT mode");
86 | monthView.setMonthDayClickListener(new MonthView.OnMonthDayClickListener() {
87 | @Override
88 | public void onMonthDayClick(FullDay day) {
89 | if(!SCDateUtils.isMonthDay(monthView.getYear(), monthView.getMonth(),
90 | day.getYear(), day.getMonth()))
91 | return;
92 | switch (mode){
93 | case INTERVAL:
94 | intervalSelect(monthView, day);
95 | break;
96 | case SEGMENT:
97 | segmentSelect(monthView, day);
98 | break;
99 | }
100 | }
101 | });
102 | }
103 |
104 | private void segmentSelect(MonthView monthView, FullDay ssDay) {
105 | if(segmentSelectListener.onInterceptSelect(ssDay)) return;
106 |
107 | if(startSelectedRecord.day == null && endSelectedRecord.day == null){ // init status
108 | startSelectedRecord.day = ssDay;
109 | monthView.addSelectedDay(ssDay);
110 | }else if(endSelectedRecord.day == null){ // start day is ok, but end day not
111 |
112 | if(startSelectedRecord.day.getDay() != ssDay.getDay()){
113 | if(startSelectedRecord.day.getDay() < ssDay.getDay()){
114 | if(segmentSelectListener.onInterceptSelect(startSelectedRecord.day, ssDay)) return;
115 | for (int day = startSelectedRecord.day.getDay(); day <= ssDay.getDay(); day++){
116 | monthView.addSelectedDay(new FullDay(monthView.getYear(), monthView.getMonth(), day));
117 | }
118 | endSelectedRecord.day = ssDay;
119 | }else if(startSelectedRecord.day.getDay() > ssDay.getDay()){
120 | if(segmentSelectListener.onInterceptSelect(ssDay, startSelectedRecord.day)) return;
121 | for (int day = ssDay.getDay(); day <= startSelectedRecord.day.getDay(); day++){
122 | monthView.addSelectedDay(new FullDay(monthView.getYear(), monthView.getMonth(), day));
123 | }
124 | endSelectedRecord.day = startSelectedRecord.day;
125 | startSelectedRecord.day = ssDay;
126 | }
127 | segmentSelectListener.onSegmentSelect(startSelectedRecord.day, endSelectedRecord.day);
128 | }else{
129 | // selected the same day when the end day is not selected
130 | segmentSelectListener.selectedSameDay(ssDay);
131 | monthView.clearSelectedDays();
132 | startSelectedRecord.reset();
133 | endSelectedRecord.reset();
134 | }
135 |
136 | }else { // start day and end day is ok
137 | monthView.clearSelectedDays();
138 | monthView.addSelectedDay(ssDay);
139 | startSelectedRecord.day = ssDay;
140 | endSelectedRecord.reset();
141 | }
142 | }
143 |
144 | protected void intervalSelect(MonthView monthView, FullDay day) {
145 | if(monthView.getSelectedDays().contains(day)) {
146 | sDays.remove(day);
147 | monthView.removeSelectedDay(day);
148 | if(intervalSelectListener.onInterceptSelect(sDays, day)) return;
149 | } else {
150 | if(intervalSelectListener.onInterceptSelect(sDays, day)) return;
151 | sDays.add(day);
152 | monthView.addSelectedDay(day);
153 | }
154 | intervalSelectListener.onIntervalSelect(sDays);
155 | }
156 |
157 | public void setIntervalSelectListener(IntervalSelectListener intervalSelectListener) {
158 | this.intervalSelectListener = intervalSelectListener;
159 | }
160 |
161 | public void setSegmentSelectListener(SegmentSelectListener segmentSelectListener) {
162 | this.segmentSelectListener = segmentSelectListener;
163 | }
164 |
165 | public List getIntervalSelectedDays() {
166 | return sDays;
167 | }
168 |
169 | public static class SelectedRecord implements Parcelable {
170 | public int position = -1;
171 | public FullDay day;
172 |
173 | public boolean isRecord(){
174 | return position >= 0 && day != null;
175 | }
176 |
177 | public void reset(){
178 | position = -1;
179 | day = null;
180 | }
181 |
182 | @Override
183 | public int describeContents() {
184 | return 0;
185 | }
186 |
187 | @Override
188 | public void writeToParcel(Parcel dest, int flags) {
189 | dest.writeInt(this.position);
190 | dest.writeParcelable(this.day, 0);
191 | }
192 |
193 | public SelectedRecord() {
194 | }
195 |
196 | @Override
197 | public String toString() {
198 | return "SelectedRecord{" +
199 | "position=" + position +
200 | ", day=" + day +
201 | '}';
202 | }
203 |
204 | protected SelectedRecord(Parcel in) {
205 | this.position = in.readInt();
206 | this.day = in.readParcelable(FullDay.class.getClassLoader());
207 | }
208 |
209 | public static final Creator CREATOR = new Creator() {
210 | public SelectedRecord createFromParcel(Parcel source) {
211 | return new SelectedRecord(source);
212 | }
213 |
214 | public SelectedRecord[] newArray(int size) {
215 | return new SelectedRecord[size];
216 | }
217 | };
218 | }
219 |
220 | @IntDef({INTERVAL, SEGMENT})
221 | public @interface Mode{}
222 |
223 | @Override
224 | public int describeContents() {
225 | return 0;
226 | }
227 |
228 | @Override
229 | public void writeToParcel(Parcel dest, int flags) {
230 | dest.writeInt(this.mode);
231 | dest.writeParcelable(this.startSelectedRecord, flags);
232 | dest.writeParcelable(this.endSelectedRecord, flags);
233 | dest.writeTypedList(sDays);
234 | }
235 |
236 | protected SingleMonthSelector(Parcel in) {
237 | this.mode = in.readInt();
238 | this.startSelectedRecord = in.readParcelable(SelectedRecord.class.getClassLoader());
239 | this.endSelectedRecord = in.readParcelable(SelectedRecord.class.getClassLoader());
240 | this.sDays = in.createTypedArrayList(FullDay.CREATOR);
241 | }
242 |
243 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
244 | @Override
245 | public SingleMonthSelector createFromParcel(Parcel source) {
246 | return new SingleMonthSelector(source);
247 | }
248 |
249 | @Override
250 | public SingleMonthSelector[] newArray(int size) {
251 | return new SingleMonthSelector[size];
252 | }
253 | };
254 | }
255 |
--------------------------------------------------------------------------------
/library/src/main/res/color/color_dayview_text_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/drawable_dayview_text_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/shape_dayview_text_bg_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/shape_dayview_text_bg_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/layout_dayview_default.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
18 |
19 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #33ccff
4 | #000000
5 | #ffffff
6 | #999999
7 | #dddddd
8 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16sp
4 | 30dp
5 | 15dp
6 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------